出于某种原因,我似乎无法将我的课程数组存储到设置中。下面的代码:如何将特定类型的数组存储到我的设置文件中?
var newLink = new Link();
Properties.Settings.Default.Links = new ArrayList();
Properties.Settings.Default.Links.Add(newLink);
Properties.Settings.Default.Save();
在我Settings.Designer.cs我指定的字段是一个数组列表:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::System.Collections.ArrayList Links {
get {
return ((global::System.Collections.ArrayList)(this["Links"]));
}
set {
this["Links"] = value;
}
}
出于某种原因,它不会保存任何数据,即使Link类是可序列化的,我已经测试过它。
“我看起来不像”你怎么看?抛出异常吗?加载时列表是否为空?没有重新加载是空的? – Foxfire 2010-05-03 23:52:36
列表是空的,没有抛出异常。不知何故,它不会序列化我的链接。 – 2010-05-03 23:54:04
数据是否包含在设置文件中(这是一个XML文件,因此您可以轻松检查)? – Foxfire 2010-05-03 23:56:24