所以我需要使用一个键,子键和值创建一个数据结构。以及添加键,子键和值的方法。
<< [Key是unique,并且可以具有multiple Sub Keys。
Sub Key
在Key内部的上下文中为uniques,并且可以具有多个Values。Values
在Sub Key的上下文中是unique。我想到的第一个数据结构是字典
(执行时间对任务很重要)。然后我创建了以下字典。 public class NewCollection : IHoplonCollection
{
class SubIndexAndValue
{
public int subIndex;
public List<string> Value = new List<string>();
}
class DataStructure : IComparable<DataStructure>
{
public string Key;
public List<SubIndexAndValue> subIndexValue = new List<SubIndexAndValue>();
public int CompareTo(DataStructure other)
{
if (Key.CompareTo(other.Key) > 0)
{
return 1;
}else if (Key.CompareTo(other.Key) < 0)
{
return -1;
}else
{
return 0;
}
}
}
SortedDictionary<DataStructure, SubIndexAndValue> colList = new SortedDictionary<DataStructure, SubIndexAndValue>();
public bool Add(string Key, int subIndex, string Value)
{
return true;
}
因此,您可以看到方法将收到Key,Sub Key和Value。将来,我将需要执行CRUD并对数据进行排序。Add
我的问题是,我该如何处理?我如何使用Contains()之类的方法来检查是否已使用此数据结构在字典中插入一个
Value
(字符串)?也许有一种更简单的方法可以做到这一点。谢谢。Dictionary<string,Dictionary<int,HashSet<string>>>
第一个字典包含string
(Key)的键-值对的列表,对于每个键-值对,该值都是另一个字典,其键是唯一的
string
(SubKey ),值是HashSet<string>
,这是唯一字符串的列表。