排序汉语词典键和值?汉语词典

由网友(wifi名字大全)分享简介:如果我想在C#中的字典,它的键,它的值确定的顺序进行排序。像降序由其值和内那些具有相同的值,由它的关键降。这似乎很可能只能通过钥匙或只按值进行排序,但两者是很烦人的。解决方案 使用System.Linq的;...IOrderedEnumerable< KeyValuePair< TKEY的,TVal...

如果我想在C#中的字典,它的键,它的值确定的顺序进行排序。像降序由其值和内那些具有相同的值,由它的关键降。这似乎很可能只能通过钥匙或只按值进行排序,但两者是很烦人的。

解决方案

 使用System.Linq的;
...
IOrderedEnumerable< KeyValuePair< TKEY的,TValue>> sortedCollection = myDictionary
                    .OrderByDescending(X => x.Value)
                    .ThenByDescending(X => x.Key);
 

What if I want to sort a dictionary in C# with the order determined by its key AND its value. Like descending order by its value and within those having the same value, descending by its key. It seems quite possible to sort only by key or only by value, but by both is quite annoying.

解决方案 汉语词典 原名国语词典

using System.Linq;
...
IOrderedEnumerable<KeyValuePair<TKey, TValue>> sortedCollection = myDictionary
                    .OrderByDescending(x => x.Value)
                    .ThenByDescending(x => x.Key);

阅读全文

相关推荐

最新文章