【发布时间】:2010-11-30 12:45:23
【问题描述】:
如何从可能有重复值的字典中创建没有重复值的字典?
IDictionary<string, string> myDict = new Dictionary<string, string>();
myDict.Add("1", "blue");
myDict.Add("2", "blue");
myDict.Add("3", "red");
myDict.Add("4", "green");
uniqueValueDict = myDict.???
编辑:
-我不在乎保留哪个密钥。 - 有没有使用 Distinct() 操作的东西?
【问题讨论】:
-
您要保留哪个键?
"1"、"2",还是没有? -
我认为您需要提供有关独特制作功能行为的更多信息。对于蓝色,应该保留哪个键,1 还是 2?
标签: c# linq .net-3.5 dictionary