
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Array.LastIndexOf(T[], T) Method in C#
The Array.LastIndexOf() method in C# is used to search for the specified object and returns the index of the last occurrence within the entire Array.
Syntax
Following is the syntax −
public static int LastIndexOf<T> (T[] array, T val);
Above, the parameter arr is the one-dimensional, zero-based Array to search, whereas Val is the object to locate in an array.
Example
Let us now see an example to implement the Array.LastIndexOf() method −
using System; public class Demo{ public static void Main(){ Console.WriteLine("Array elements..."); string[] arr = { "car", "bike", "truck", "bus"}; for (int i = 0; i < arr.Length; i++){ Console.Write("{0} ", arr[i]); } Console.WriteLine(); int lastIndex = Array.LastIndexOf(arr, "bus"); Console.WriteLine("Last Ocurrence of element bus is at index = "+lastIndex); } }
Output
This will produce the following output −
Array elements... car bike truck bus Last Ocurrence of element bus is at index = 3
- Related Articles
- Array.AsReadOnly(T[]) Method in C#
- The toArray(T[] a) T method of Java AbstractCollection class
- The toArray(T[]) method of AbstractSequentialList in Java
- Java String lastIndexOf() method example.
- The toArray(T[] a) method of CopyOnWriteArrayList in Java
- Find the value of t, if $0.1(t-3)=0.15(t-4)$​.
- The lastIndexOf() method of CopyOnWriteArrayList in Java
- Find the value of $t$, if \( \frac{3 t-2}{4}-\frac{2 t+3}{3}=\frac{2}{3}-t \).
- Why can't static method be abstract in Java?
- Construct SLR (1) parsing table for the grammar\n1. E → E + T\n2. E → T\n3. T → T * F\n4. T → F\n5.F → (E)\n6.F → id
- Add the following:-$t-8tz, 3tz-z ,z-t$.
- Difference Between T-Mobile Internet and T-Mobile Web
- The lastIndexOf() method of AbstractList class in Java
- Getting class of given method using T-code SE80 in SAP
- Find FIRST & FOLLOW for the following Grammar\nE → E + T|T\nT → T ∗ F|F\nF → (E)|id

Advertisements