【发布时间】:2017-05-09 20:44:13
【问题描述】:
我对字典排序有疑问:
SortedDictionary<string, List<int>> mySortedDictionary;
我想用来自 mySortedDictionary 的数据创建新的Dictionary<string,List<int>>,它按值(确切地按列表中的项目数,换句话说 List.Count)升序排序,而 lists.Count 相同,键是按字母升序排序。谁能告诉我如何做到这一点?
mySortedDictionary.Add("orange", List<2,9>) //List.Count = 2
mySortedDictionary.Add("money", List<2,4,8,9>) //4
mySortedDictionary.Add("monkey", List<2,4,9>) //3
mySortedDictionary.Add("hokey", List<2,5,9>) //3
//result: order in new sorted Dictionary//
"orange", List<2,9>
"hokey", List<2,5,9>
"monkey", List<2,4,9>
"money", List<2,4,8,9>
提前感谢您的帮助!!!
【问题讨论】:
-
字典本身没有任何顺序。即使您想出一种算法以特定顺序插入字典,也不能保证您会以相同的顺序返回它们。
-
@Partha
SortedDictionary有订单(key)
标签: c# linq sorting dictionary