多字段排序

添加到 LINQ 查询结果中的Take()扩展方法用于提取前   个结果:

private static void Ordering()
{ var racers = (from r in Formula1.GetChampions()
orderby r.Country, r.LastName, r.FirstName
select r).Take(); 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(); foreach (var racer in racers)
{
Console.WriteLine("{0:C}: {0:L}, {0:F}", racer); //属性名的第一个字母
} }
04-02 06:37