用LINQ对Dictionary排序-创新互联
代码如下 :![用LINQ对Dictionary
排序 用LINQ对Dictionary
排序](/upload/otherpic30/2131606.jpg)
网页题目:用LINQ对Dictionary排序-创新互联
标题来源:http://myzitong.com/article/doppoc.html
![用LINQ对Dictionary
排序 用LINQ对Dictionary
排序](/upload/otherpic30/2131606.jpg)
static void Main(string[] args)
{
Dictionary di = new Dictionary();
di.Add(9, 1);
di.Add(0, 6);
di.Add(2, 8);
var sortedDict = (from entry in di orderby entry.Key ascending select entry)
.ToDictionary(pair=> pair.Key, pair => pair.Value);
foreach (var pair in di)
{
Console.WriteLine("{0},{1}", pair.Key, pair.Value);
}
Console.WriteLine("--------------------");
foreach (var pair in sortedDict)
{
Console.WriteLine("{0},{1}", pair.Key, pair.Value);
}
Console.ReadLine();
}
方法来自stackoverflow
http://stackoverflow.com/questions/289/how-do-you-sort-a-c-sharp-dictionary-by-value
网页题目:用LINQ对Dictionary排序-创新互联
标题来源:http://myzitong.com/article/doppoc.html