我知道:
应用程序设置可以存储为XML可序列化的任何数据类型,或者具有实现ToString / FromString的TypeConverter。最常见的类型是String,Integer和Boolean,但您也可以将值存储为Color,Object或连接字符串。
我有一个ListDictionary类设置 - 这是可序列化的,但每次我再次启动我的应用程序时它尽管创建,分配和保存ListDictionary到我的设置是空的:
Properties.Settings.Default.Preferences = new System.Collections.Specialized.ListDictionary();
Properties.Settings.Default.Preferences.Add(1, "test");
Properties.Settings.Default.Save();
如何将此类用作应用程序设置?我需要字典类型集合作为设置...
答案 0 :(得分:1)
我希望你尝试一系列的东西。
http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx 将2个字符串(DictionaryKey和Dictionaryvalue)添加到设置中,并将范围设置为user,将值设置为空白
进行2次刺痛设置并执行此操作
Properties.Settings.Default.Dictionarykey = "";// To empty previous settings
Properties.Settings.Default.Dictionaryvalue = "";// To empty previous settings
for (int i = 0; i < yourdictionarycount; i++ )
{
Properties.Settings.Default.Dictionarykey += i + "#"; // or any other value
Properties.Settings.Default.Dictionaryvalue += "test" + "#"; // or any other value
}
Properties.Settings.Default.Save();
当您检索值
时使用此代码:
public Dictionary<int, string> savedsettings = new Dictionary<int, string>();
string[] eachkey = Properties.Settings.Default.Dictionarykey.Split('#');
string[] value = Properties.Settings.Default.Dictionaryvalue.Split('#');
for (int j = 0; j < eachkey.Length; j++)
{
savedsettings.Add(eachkey[i], eachvalue[i]);
}
//just to check if the values are being retrieved properly
Messagebox.Show(Properties.Settings.Default.Dictionarykey);
此致
Vivek Sampara