C# Linq Skip() 方法


使用 Skip() 方法跳过元素并返回剩余元素。

下面是一个数组。

int[] marks = { 80, 55, 79, 99 };

现在,让我们使用 Lambda 表达式跳过 2 个元素,但这须在按降序排列这些元素之后进行。

IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).Skip(2);

示例

using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
   public static void Main() {
      int[] marks = { 80, 55, 79, 99 };
      IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).Skip(2);
      Console.WriteLine("Skipped the result of 1st two students...");
      foreach (int res in selMarks) {
         console.WriteLine(res);
      }
   }
}

更新于: 23-6-2020

2K+ 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.