为什么列表<string>保存在应用程序设置中,而链接列表<string>没有?



这是我的Settings.setting文件:

<Setting Name="AutoCompleteList" Type="System.Collections.Generic.LinkedList&lt;string&gt;" Scope="User">
<Value Profile="(Default)" />
</Setting>

这是我的设置。Designer.cs:

public global::System.Collections.Generic.LinkedList<string> AutoCompleteList {
get {
return ((global::System.Collections.Generic.LinkedList<string>)(this["AutoCompleteList"]));
}
set {
this["AutoCompleteList"] = value;
}
}

Programs.cs

class Program
{
private static LinkedList<string> _autoCompleteList;
static void Main()
{
_autoCompleteList = new LinkedList<string>((new[] {"one", "two"}));

Settings.Default.AutoCompleteList = _autoCompleteList;
Settings.Default.Save(); //Nothing is saved. (Silently and without any error)

_autoCompleteList = Settings.Default.AutoCompleteList; //null
}
}

如果我使用List<string>而不是LinkedList<string>,所有的东西都可以工作;但我需要LinkedList,因为它可以更容易地访问前一个和下一个元素。对使用List应用内设置并在运行时将其加载到LinkedList中是可能的,但我想知道为什么LinkedList不能保存在应用内设置中。

此外,我应该明确表示,我的所有设置的范围都是";用户";

链表是一种数据结构,它只在内存中实现,因为每个元素也链接到另一个元素。这就是它无法保存的原因。它只能在内存中实现。

相关内容

最新更新