【问题标题】:Base way to store the Dictionary values存储字典值的基本方式
【发布时间】:2014-03-14 12:27:57
【问题描述】:

我有一个需要存储值的场景。我有一个要保存值的应用程序。 我正在开发 Windows 8 Phone 应用程序。

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

喜欢

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

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

等等……

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

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

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

【问题讨论】:

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


【解决方案1】:

将其存储在数据集中不是更好吗?您拥有的表/列/行信息的数量没有限制,您可以使用 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());
    }
}

【讨论】:

猜你喜欢
  • 2021-06-21
  • 1970-01-01
  • 2012-08-03
  • 2015-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多