
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# Linq SkipLast Method
Skip elements from the end and return the remaining elements using the SkipLast() method.
The following is an array.
int[] marks = { 45, 88, 50, 90, 95, 85 };
Now, let us skip two elements from the end using SkipLast() and Lambda Expressions, but this is done after arranging the elements in descending order.
IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipLast(2);
Example
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); } }
Output
Skipped the marks of last two students... 95 90 88 85
Advertisements