赞
踩
字典的排序,简单做个笔记,方便查询(引用命名空间using System.Linq;):
- Dictionary<int, int> tempDict = new Dictionary<int, int>();
- var sortResult1 = from pair in tempDict orderby pair.Value descending select pair; //以字典Value值逆序排序[降序]
- var sortResult2 = from pair in tempDict orderby pair.Key descending select pair; //以字典Key值逆序排序[降序]
- var sortResult3 = from pair in tempDict orderby pair.Key ascending select pair; //以字典Key值顺序排序[升序]
- var sortResult4 = from pair in tempDict orderby pair.Value ascending select pair; //以字典Value值顺序排序[升序]
总结:
Dictionary<int, int> sortResult1 = from pair in tempDict orderby pair.Value descending select pair; //以字典Value值逆序排序
- public class Info
- {
- public int m_ID;
- }
- Dictionary<int, Info> tempDict = new Dictionary<int, Info>();
- var sortResult1 = from pair in tempDict orderby pair.Value.m_ID descending select pair; //以字典Value值的字段 m_ID 逆序排序
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_42205218/article/details/105934030
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。