日期:2014-05-18 浏览次数:21235 次
Dictionary<int, int> dic = new Dictionary<int, int>(); dic.Add(1, 158); dic.Add(5, 25); dic.Add(3, 215); dic.Add(2, 369); dic.Add(4, 147); var result = from pair in dic orderby pair.Key select pair; foreach (KeyValuePair<int, int> pair in result) { Console.WriteLine("Key:{0}, Value:{1}", pair.Key, pair.Value); } Console.ReadKey();
Dictionary<int, int> dic = new Dictionary<int, int>(); dic.Add(1, 158); dic.Add(5, 25); dic.Add(3, 215); dic.Add(2, 369); dic.Add(4, 147); var result = from pair in dic orderby pair.Key descending select pair; foreach (KeyValuePair<int, int> pair in result) { Console.WriteLine("Key:{0}, Value:{1}", pair.Key, pair.Value); } Console.ReadKey();
------解决方案--------------------
呵呵,LINQ基本和SQL一样的。