我有以下字典:在字典的鍵中刪除重複
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'是三個不同的值,因此它們不是重複的。 –