存储Dictionary值的基本方法

时间:2014-03-14 12:27:58

标签: c# wpf windows-phone-8 dictionary

我有一个场景,我需要存储值。我有一个应用程序,我想保存值。 我正在使用Windows 8 Phone应用程序。

它有多个主题,每个主题将有3个不同的值存储。

喜欢

1) IT  -> employees -25
       -> resources -25
       -> buildings -32

2) College -> students -33
           -> buildings -4
           -> faculty -35

依旧......

现在我在Dictionary<string,string>中有这些值每次当我将这些值添加到字典时,我需要存储这些值以将其重新显示回来并显示。

这些值应该存在,直到从设备上卸载应用程序,如果我想清除保存的结果,我也应该能够这样做。

实现这一目标的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

将它存储在数据集中会不会更好?您拥有的表/列/行信息量没有限制,您可以使用LINQ来快速查询数据!

这是一个例子:)希望这有帮助!

using System;
using System.Data;

class Program
{
  static void Main()
  {
    // Create two DataTable instances.
    DataTable table1 = new DataTable("patients");
    table1.Columns.Add("name");
    table1.Columns.Add("id");
    table1.Rows.Add("sam", 1);
    table1.Rows.Add("mark", 2);

    DataTable table2 = new DataTable("medications");
    table2.Columns.Add("id");
    table2.Columns.Add("medication");
    table2.Rows.Add(1, "atenolol");
    table2.Rows.Add(2, "amoxicillin");

    // Create a DataSet and put both tables in it.
        DataSet set = new DataSet("office");
    set.Tables.Add(table1);
    set.Tables.Add(table2);

    // Visualize DataSet.
    Console.WriteLine(set.GetXml());
    }
}