Mono Class Library: System.Array Overview | MembersSystem.Array.LastIndexOf Method |
Searches the specified one-dimensional Array, returning the index of the last occurrence of the specified object. [Edit]
|
A int containing the index of the last occurrence in array of value, if found; otherwise, array.GetLowerBound(0) - 1.Note: For a vector, if value is not found, the return value will be -1. This provides the caller with a standard code for the failed search.[Edit]
Type Reason ArgumentNullException array is null . [Edit] RankException array has more than one dimension. [Edit]
This version of Array.LastIndexOf(Array, object) is equivalent to Array.LastIndexOf(Array, object)(array, value, (array.GetLowerBound(0) + array.Length - 1), array.Length).
The elements are compared using object.Equals(object).
[Edit]
The following example demonstrates the Array.LastIndexOf(Array, object) method.
C# Example using System; public class ArrayLastIndexOfExample { public static void Main() { int[] intAry = { 0, 1, 2, 0, 1 }; Console.Write( "The values of the array are: "); foreach( int i in intAry ) Console.Write( "{0,5}", i ); Console.WriteLine(); int j = Array.LastIndexOf( intAry, 1 ); Console.WriteLine( "The last occurrence of 1 is at index {0}", j ); } }The output is
The values of the array are: 0 1 2 0 1
The last occurrence of 1 is at index 4
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0