Array.LastIndexOf Method (Array, Object, Int32, Int32)

Searches for the specified object and returns the index of the last occurrence within the range of elements in the one-dimensional Array that contains the specified number of elements and ends at the specified index.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static int LastIndexOf(
	Array array,
	Object value,
	int startIndex,
	int count


Type: System.Array
The one-dimensional Array to search.
Type: System.Object
The object to locate in array.
Type: System.Int32
The starting index of the backward search.
Type: System.Int32
The number of elements in the section to search.

Return Value

Type: System.Int32
The index of the last occurrence of value within the range of elements in array that contains the number of elements specified in count and ends at startIndex, if found; otherwise, the lower bound of the array minus 1.


array is null.


startIndex is outside the range of valid indexes for array.


count is less than zero.


startIndex and count do not specify a valid section in array.


array is multidimensional.

The one-dimensional Array is searched backward starting at startIndex and ending at startIndex minus count plus 1, if count is greater than 0.

The elements are compared to the specified value using the Object.Equals method. If the element type is a nonintrinsic (user-defined) type, the Equals implementation of that type is used.

Since most arrays will have a lower bound of zero, this method would generally return –1 when value is not found. In the rare case that the lower bound of the array is equal to Int32.MinValue and value is not found, this method returns Int32.MaxValue, which is System.Int32.MinValue - 1.

This method is an O(n) operation, where n is count.

In the .NET Framework version 2.0, this method uses the Equals and CompareTo methods of the Array to determine whether the Object specified by the value parameter exists. In the earlier versions of the .NET Framework, this determination was made by using the Equals and CompareTo methods of the value Object itself.


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.