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); } } }
廣告