- 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 find the last matching element in an array
To find the last matching element, use the Array.LastIndexOf method. Returns -1 if the element isn’t present in the integer array.
The following is the array −
int[] val = { 97, 45, 76, 21, 89, 45 };
Now, let’s say you need to search the last Index of element 45. For that, use Array.LastIndexOf() method −
int res = Array.LastIndexOf(val, 45);
The following is an example −
Example
using System; using System.Text; public class Demo { public static void Main() { int[] val = { 97, 45, 76, 21, 89, 45 }; // last Index of element 45 int res = Array.LastIndexOf(val, 45); // Display the index Console.WriteLine("Index of element 45 is = "+res); } }
Output
Index of element 45 is = 5
- Related Articles
- C# program to get the last element from an array
- Program to get the last element from an array using C#
- C# Program to find the smallest element from an array
- C# Program to find the largest element from an array
- Program to find largest element in an array in C++
- C++ Program to Find Largest Element of an Array
- C# program to find maximum and minimum element in an array
- Program to find the minimum (or maximum) element of an array in C++
- Python Program to find the largest element in an array
- PHP program to find the minimum element in an array
- PHP program to find the maximum element in an array
- Recursive program to find an element in an array linearly.
- C++ Program to Find Minimum Element in an Array using Linear Search
- C++ Program to Find Maximum Element in an Array using Binary Search
- Python Program to find largest element in an array

Advertisements