SkipLast() 메서드를 사용하여 끝에서 요소를 건너뛰고 나머지 요소를 반환합니다.
다음은 배열입니다.
int[] marks = { 45, 88, 50, 90, 95, 85 }; 이제 SkipLast()와 Lambda 식을 사용하여 끝에서 두 개의 요소를 건너뛰도록 합시다. 하지만 이것은 요소를 내림차순으로 정렬한 후에 수행됩니다.
IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2);
예
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] marks = { 45, 88, 50, 90, 95, 85 };
IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2);
Console.WriteLine("Skipped the marks of last two students...");
foreach (int res in selMarks)
Console.WriteLine(res);
}
} 출력
Skipped the marks of last two students... 95 90 88 85