扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
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
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流