赞
踩
C# Dictionary<TKey,TValue> 表示键和值的集合,可以很方便的使用linq进行排序操作。
以<string,string>类型为例: 新建控制台应用,并用下面代码替换掉 Program.cs 的代码
using System; using System.Collections.Generic; using System.Linq; namespace DicSort { class Program { static void Main(string[] args) { Console.WriteLine("kvs: \n---------"); var kvs = new Dictionary<string, string>(); kvs.Add("name", "wufan"); kvs.Add("id", "1"); kvs.Add("age", "26"); PrintDic(kvs); Console.WriteLine("--------\n\n orderedKvs: \n---------"); var orderedKvs= kvs.OrderBy(x => x.Key).ToDictionary(x=>x.Key,x=>x.Value); PrintDic(orderedKvs); Console.Read(); } st
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。