- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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# Queryable TakeLast() Method
Get specified number of elements from the end using the TakeLast() method.
The following is our array.
int[] pages = { 492, 290, 129, 602, 152 };
Now, use OrderBy to order the elements in ascending order. Then use the TakeLast() method to get specified number of elements from the end.
marks.AsQueryable().OrderByDescending(s => s).Take(5);
Let us see the complete example.
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { // pages of books int[] pages = { 492, 290, 129, 602, 152 }; // get pages of last two books IEnumerable<int> last = pages.AsQueryable().OrderBy(s => s).TakeLast(2); foreach (int res in last) { Console.WriteLine(res); } } }
Output
492 602
Advertisements