- 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# Linq Last() Method
Get the last element from a sequence using the Linq Last() method.
The following is our array.
int[] val = { 10, 20, 30, 40 };
Now, get the last element.
val.AsQueryable().Last();
Example
using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { int[] val = { 10, 20, 30, 40 }; // getting last element int last_num = val.AsQueryable().Last(); Console.WriteLine("Last element: "+last_num); } }
Output
Last element: 40
Advertisements