C#:按降序排序字典

时间:2010-05-11 01:06:57

标签: c# dictionary

如何按照值的降序对键值对进行排序?

foreach (KeyValuePair<string, int> item in keyvalue.OrderBy(key => key.Value))
            {
            } 

1 个答案:

答案 0 :(得分:39)

使用OrderByDescending代替OrderBy

foreach (var item in keyvalue.OrderByDescending(key => key.Value))
{

}