赞
踩
- //C#2.0 (VS2005)实现方法:
-
- private void dicSort(ref Dictionary<string, int> dic)
- {
- List<KeyValuePair<string, int>> myList = new List<KeyValuePair<string, int>>(dic);
-
- myList.Sort(delegate (KeyValuePair<string, int> s1, KeyValuePair<string, int> s2)
- {
- return s2.Value.CompareTo(s1.Value);
- });
- dic.Clear();
-
- foreach (KeyValuePair<string, int> pair in myList)
- {
- dic.Add(pair.Key, pair.Value);
- }
- }
-
-
- C#3.0 Lambda表达式 (VS2008)的实现方法:
-
- var list = dic.OrderBy(s => s.Value);
-
- C#3.0 Linq (VS2008)的实现方法:
-
- var dicSort = from d in dic
-
- orderby d.Value
-
- ascending
-
- select d;
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。