C# LINQ 基础 互动版

Skip

Skip用于从输入序列中跳过指定数量的元素,返回由序列中剩余元素所组成的新元素。用法如下代码:

static void Main()
{
  int[] grades = { 59, 82, 70, 56, 92, 98, 85 };
  IEnumerable&ltint&gt lowerGrades =
  grades.OrderByDescending(g => g).Skip(3);
  Console.WriteLine("All grades except the top three are:");
  foreach (int grade in lowerGrades)
  {
      Console.WriteLine(grade);
  }
}

运行结果为:

All grades except the top three are:
82
70
59
56