Fre*_*dom 17 .net c# sorting dictionary
如果我想在C#中对字典进行排序,其顺序由其键及其值确定.类似于其值的降序和具有相同值的降序,按其键降序.似乎很有可能只按键或仅按值排序,但两者都非常烦人.
Den*_*aub 25
using System.Linq;
...
IOrderedEnumerable<KeyValuePair<TKey, TValue>> sortedCollection = myDictionary
.OrderByDescending(x => x.Value)
.ThenByDescending(x => x.Key);
Run Code Online (Sandbox Code Playgroud)