Dictionary<char, int> dic = new Dictionary<char, int>();
dic.Add('a', 1);
dic.Add('b', 2);
dic.Add('c', 1);
dic.Add('d', 3);
dic.Add('e', 8);
结果:
①dicsort1 :按key值升序
Dictionary<char, int> dicsort1 = dic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);//按key值升序
②dicsort2 :按key值降序
Dictionary<char, int> dicsort2 = dic.OrderByDescending(o => o.Key).ToDictionary(o => o.Key, p => p.Value);//按key值降序
③dicsort3:按Value值升序
Dictionary<char, int> dicsort3 = dic.OrderBy(o => o.Value).ToDictionary(o => o.Key, p => p.Value);//按Value值升序
④dicsort4:按Value值降序
Dictionary<char, int> dicsort4 = dic.OrderByDescending(o => o.Value).ToDictionary(o => o.Key, p => p.Value);//按Value值降序