LINQ

var racers = Formula1.GetChampions().
                Where(r => r.Wins > 15 && (r.Country == "Brazil" || r.Country == "Austria")).
                Select(r=>r);
            foreach (var item in racers)
            {
                Console.WriteLine("{0:A}",item);
            }

索引传递

var racers = Formula1.GetChampions().Where((r, index) => r.LastName.StartsWith("A") && index % 2 != 0);
            foreach (var item in racers)
            {
                Console.WriteLine("{0:A}", item);
            }

linq分组、排序、选择特定值(其中Coun,C可以理解为结果的属性)

var country = Formula1.GetChampions().GroupBy(r => r.Country).OrderByDescending(g => g.Count()).
ThenBy(g => g.Key).Where(g => g.Count() > 2).Select(g => new { Coun = g.Key, C = g.Count() });

分页分区

int pageSize = 5;
int pageNumber = (int)Math.Ceiling(Formula1.GetChampions().Count() / (double)pageSize);
for (int page = 0; page < pageNumber; page++)
{
Console.WriteLine("page {0}",page);
var racers = (from r in Formula1.GetChampions() orderby r.LastName select r.FirstName + " " + r.LastName).Skip(page * pageSize).Take(pageSize);
foreach (var item in racers)
{
Console.WriteLine(item);
}
}

原文地址:https://www.cnblogs.com/yj2010/p/4122779.html