Bỏ qua các phần tử từ cuối và trả về các phần tử còn lại bằng phương thức SkipLast ().
Sau đây là một mảng.
int[] marks = { 45, 88, 50, 90, 95, 85 }; Bây giờ, chúng ta hãy bỏ qua hai phần tử ở phần cuối bằng SkipLast () và Lambda Expressions, nhưng điều này được thực hiện sau khi sắp xếp các phần tử theo thứ tự giảm dần.
IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2);
Ví dụ
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);
}
} Đầu ra
Skipped the marks of last two students... 95 90 88 85