我有以下字典:在字典的键中删除重复
Dictionary<string, string> test = new Dictionary<string, string>();
test.Add("1|1", "blue");
test.Add("1|2", "Nice");
test.Add("1|3", "Jaish");
test.Add("2|2", "Muna");
test.Add("3|1", "haha");
test.Add("3|2", "green");
test.Add("4|1", "red");
Dictionary<string, string> test2 = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> entry in test)
{
if (!test2.ContainsValue(entry.Key))
test2.Add(entry.Key, entry.Key);
}
我想删除下面的重复值:
test.Add("1|2", "Nice");
test.Add("1|3", "Jaish");
test.Add("3|2", "green")
因此,移除重复的Dictionary
的密钥计数后应4.
它们不是重复的。你不能在字典中有重复的键 – Habib
我知道字典键不包含重复项,但我想要唯一的字典键数。 – KCS
你对*重复*的定义是什么? '1 | 2','1 | 3'和'3 | 2'是三个不同的值,因此它们不是重复的。 –