

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Program to get the last element from an array using C#
Declare an array and add elements.
int[] val = { 5, 8, 15, 25, 40, 55, 80, 100 };
Now, use the Queryable Last() method to get the last element.
val.AsQueryable().Last();
Let us see the complete code.
Example
using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { int[] val = { 5, 8, 15, 25, 40, 55, 80, 100 }; int last_num = val.AsQueryable().Last(); Console.WriteLine("Last element: "+last_num); } }
Output
Last element: 100
- Related Questions & Answers
- C# program to get the last element from an array
- C# program to find the last matching element in an array
- C# Program to display the first element from an array
- C# Program to find the largest element from an array
- C# Program to find the smallest element from an array
- Find the position of the last removed element from the array using C++
- C# Program to find the smallest element from an array using Lambda Expressions
- C# Program to find the largest element from an array using Lambda Expressions
- Java Program to Get First and Last Elements from an Array List
- How to get the last element in JavaScript array?
- C Program to insert an array element using pointers.
- C program to delete an array element using Pointers
- C program to search an array element using Pointers.
- PHP program to delete an element from the array using the unset function
- Get the first and last item in an array using JavaScript?
Advertisements