C#: sort dictionary in descending order

后端 未结 1 2076
难免孤独
难免孤独 2021-02-18 18:06

How do I sort a keyvalue pair with descending order of their values?

foreach (KeyValuePair item in keyvalue.OrderBy(key => key.Value))
             


        
1条回答
  •  不知归路
    2021-02-18 18:42

    Use OrderByDescending instead of OrderBy.

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

    0 讨论(0)
提交回复
热议问题