【发布时间】:2015-07-24 15:56:05
【问题描述】:
我有两本这样的字典:
Dictionary<int, string> main = new Dictionary<int, string>();
Dictionary<int, string> other = new Dictionary<int, string>();
main.Add(0, "fruit;banana");
main.Add(1, "fruit;apple");
main.Add(2, "fruit;cherry");
main.Add(3, "fruit;pear");
other.Add(0, "fruit;blueberry");
other.Add(1, "fruit;pear");
other.Add(2, "fruit;orange");
我需要对这两个字典进行排序,并且在输出我想要第三个字典,其中包含所有已排序的水果
【问题讨论】:
-
第三个字典的键和值应该是什么?它们显然不能与您拥有的两个字典中的相同,因为它们之间有重复的键。
-
第三本词典应该是什么样子的?例如,我们如何处理重复键(例如
main[0]和other[0])? -
@Chris haha 我想你打败了我 :)
-
Dictionary不是指定或关心其值排序的集合类型,因此对 Dictionary 进行排序没有任何意义(但您可以将 values 排序为另一个集合或枚举)。 -
或者你可以使用SortedDictionary,如果水果是键,呵呵
标签: c# dictionary compare