ISharedPreferences 在插入时删除重复项

ISharedPreferences deletes duplicates when inserted

比如我有一个简单的列表:

List<string> s = new List<string>();
s.Add("eg1");
s.Add("eg2");
s.Add("eg3");
s.Add("eg1");

假设我现在想插入到名为 editor:

ISharedPreferences editor
editor.PutStringSet("eg", s);

现在,我想通过以下方式访问此列表:

ICollection<string> eg= prefs.GetStringSet("eg", (ICollection<string>)new HashSet<string>());
List<string> s2 = eg.ToList<string>();

问题是我的列表中有像 "eg1" 这样的重复项,但编辑器删除了它们。

我的问题是如何防止编辑器删除我列表中的重复项?

除了当前列表,您还可以存储出现次数(或索引,如果它们对您很重要):

List<string> s = new List<string>();
s.Add("eg1:[0, 3]");
s.Add("eg2:[1]");
s.Add("eg3:[2]");