- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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# program to get the last element from an array
Firstly, set an array −
string[] str = new string[]{ "Java", "HTML", "jQuery", "JavaScript", "Bootstrap" };
To get the value of the last element, get the length and display the following value −
str[str.Length - 1]
The above returns the last element.
Here is the complete code −
Example
using System; public class Demo { public static void Main() { string[] str = new string[] { "Java", "HTML", "jQuery", "JavaScript", "Bootstrap" }; Console.WriteLine("Array..."); foreach(string res in str) { Console.WriteLine(res); } Console.WriteLine("Last element: "+str[str.Length - 1]); } }
Output
Array... Java HTML jQuery JavaScript Bootstrap Last element: Bootstrap
- Related Articles
- Program to get the last element from an array using C#
- C# program to find the last matching element in an array
- Java Program to Get First and Last Elements from an Array List
- C# Program to find the smallest element from an array
- C# Program to find the largest element from an array
- C# Program to display the first element from an array
- How to get the last element in JavaScript array?
- What should be the correct Algorithm to Get Array B from Array A counting backwards from the last element in JavaScript?
- 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
- Find the position of the last removed element from the array using C++
- JavaScript code to print last element of an array
- C# Program to get distinct element from a sequence
- Get the last element from a Sorted Set in Java
- C++ Program to Find Largest Element of an Array

Advertisements