Declare an array and initialize elements.
int[] marks = { 45, 50, 60, 70, 85 };Use the SkipLast() method to skip elements of an array from the end.
IEnumerable<int> selMarks = marks.AsQueryable().SkipLast(3);
The elements are skipped and rest of the elements is returned as shown below −
Example
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);
}
}Output
Array... 45 50 60 70 85 Array after skipping last 3 elements... 45 50