如何按照值的降序对键值对进行排序?
foreach (KeyValuePair<string, int> item in keyvalue.OrderBy(key => key.Value))
{
}
答案 0 :(得分:39)
使用OrderByDescending
代替OrderBy
。
foreach (var item in keyvalue.OrderByDescending(key => key.Value))
{
}