Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
