Khai báo một mảng và khởi tạo các phần tử.
int[] marks = { 45, 50, 60, 70, 85 }; Sử dụng phương thức SkipLast () để bỏ qua các phần tử của mảng từ cuối.
IEnumerable<int> selMarks = marks.AsQueryable().SkipLast(3);
Các phần tử bị bỏ qua và phần còn lại của các phần tử được trả về như hình dưới đây -
Ví dụ
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] marks = { 45, 50, 60, 70, 85 };
Console.WriteLine("Array...");
foreach (int res in marks)
Console.WriteLine(res);
IEnumerable<int> selMarks = marks.AsQueryable().SkipLast(3);
Console.WriteLine("Array after skipping last 3 elements...");
foreach (int res in selMarks)
Console.WriteLine(res);
}
} Đầu ra
Array... 45 50 60 70 85 Array after skipping last 3 elements... 45 50