C# Array LastIndexOf(T[], T)
Description
Array LastIndexOf(T[], T)
searches for the specified
object and returns the index of the last occurrence within the entire Array.
Syntax
Array.LastIndexOf(T[], T)
has the following syntax.
public static int LastIndexOf<T>(
T[] array,
T value
)
Parameters
Array.LastIndexOf(T[], T)
has the following parameters.
T
- The type of the elements of the array.array
- The one-dimensional, zero-based Array to search.value
- The object to locate in array.
Returns
Array.LastIndexOf(T[], T)
method returns The zero-based index of the last occurrence of value within the entire array,
if found; otherwise, -1.
Example
The following code example demonstrates all three generic overloads of the LastIndexOf method.
/*w w w .j a va 2 s . c om*/
using System;
public class Example
{
public static void Main()
{
string[] myValues = { "2001",
"1999",
"2000",
"1234",
"2002",
"2001",
"3211" };
Console.WriteLine(Array.LastIndexOf(myValues, "2001"));
Console.WriteLine(Array.LastIndexOf(myValues, "2001", 3));
Console.WriteLine(Array.LastIndexOf(myValues, "2001", 4, 4));
}
}
The code above generates the following result.