排序汉语词典键和值? [英] Sort a Dictionary by key AND value?

查看:126
本文介绍了排序汉语词典键和值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想在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);

这篇关于排序汉语词典键和值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆