Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to skip elements of an array from the end
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
Advertisements