我有一个项目列表。每个项目是一个包含两个字段的对象。第一个字段是类型为Dictionary<string, List<string>
的字典,第二个字段是int类型。
现在我想检查是否存在两个字段都是唯一的元素。
对于字典字段,我只关心键部分,而不是值。因此,在项之间,值部分可能相同。
这个列表中必须是键必须唯一的。
如果存在这样的元素,我希望能够获取该元素在列表中的位置。
希望清楚明了。
为了澄清:
以下是我的类
namespace Polstyr
{
class RecordItem
{
Dictionary<string, List<string>> dict;
public string MachineNr { get; set; }
public RecordItem()
{
dict = new Dictionary<string, List<string>>();
}
public void AddToDict(string value, List<string> list)
{
dict.Add(value, list);
}
public Dictionary<string, List<string>> GetDictionary
{
get
{
return dict;
}
}
}
在我的代码的另一部分,我有一个名为recordItems的List<RecordItem>
类型列表。
我想检查recordItems列表中是否有RecordItem对象,该对象基于其字段在列表中是唯一的。字典中的键必须是唯一的,MachineNr也必须是唯一的。
提前感谢。