Skip:绕过序列中指定数量的元素,然后返回其余元素。
int[] grades = { 59, 82, 70, 56, 92, 98, 85 };
Console.WriteLine("All grades except the first three:");
//前三位之外的所有元素
foreach (int grade in grades.Skip(3))
{
Console.WriteLine(grade);
}
/*
This code produces the following output:
All grades except the first three:
56
92
98
85
*/
Take :从序列的开头返回指定数量的连续元素
int[] grades = { 59, 82, 70, 56, 92, 98, 85 };
// 降序排序然后取前三
IEnumerable<int> topThreeGrades =
grades.AsQueryable().OrderByDescending(grade => grade).Take(3);
Console.WriteLine("The top three grades are:");
foreach (int grade in topThreeGrades)
Console.WriteLine(grade);
/*
This code produces the following output:
The top three grades are:
98
92
85
*/