Dictionary<string,int> dic=new Dictionary<string,int>();//键值对形式
dic.Add("beijing", 100);
dic.Add("shanghai", 200);
dic.Add("guangdong", 300);
dic.Add("shenzhen", 400);
Dictionary<string, int> dicAsc = dic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);//以key排序
foreach (KeyValuePair<string, int> dic1 in dicAsc)
a.Add("shanghai");
a.Add("beijing");
a.Add("chongqing");
a.Add("guangdong");
a.Add("guangxi");
var aAsc=a.OrderBy(o=>o);
foreach (string aAsc1 in aAsc)
Response.Write(aAsc1+"<br/>");
var aDesc = a.OrderByDescending(o => o);
foreach (string aDesc1 in aDesc)
Response.Write(aDesc1+"<br/>");
dic.Add("beijing", 100);
dic.Add("shanghai", 200);
dic.Add("guangdong", 300);
dic.Add("shenzhen", 400);
Dictionary<string, int> dicAsc = dic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);//以key排序
foreach (KeyValuePair<string, int> dic1 in dicAsc)
Response.Write(dic1+"<br>");
a.Add("shanghai");
a.Add("beijing");
a.Add("chongqing");
a.Add("guangdong");
a.Add("guangxi");
var aAsc=a.OrderBy(o=>o);
foreach (string aAsc1 in aAsc)
Response.Write(aAsc1+"<br/>");
var aDesc = a.OrderByDescending(o => o);
foreach (string aDesc1 in aDesc)
Response.Write(aDesc1+"<br/>");