LINQ 按多个字段排序
多字段排序
添加到 LINQ 查询结果中的Take()扩展方法用于提取前 10 个结果: private static void Ordering() { var racers = (from r in Formula1.GetChampions() orderby r.Country, r.LastName, r.FirstName select r).Take(10); foreach (var racer in racers) { Console.WriteLine("{0:C}: {0:L}, {0:F}", racer); //属性名的第一个字母 } } Lambda表达式 使用OrderBy()和 ThenBy()方法可以执行相同的操作: private static void Ordering() { var racers = Formula1.GetChampions(). OrderBy(r => r.Country). ThenBy(r => r.LastName). ThenBy(r => r.FirstName). Take(10); foreach (var racer in racers) { Console.WriteLine("{0:C}: {0:L}, {0:F}", racer); //属性名的第一个字母 } }
posted on 2014-03-13 16:51 alonelonly 阅读(521) 评论(0) 编辑 收藏 举报