IndexOf Method (Array, Object)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array.

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

public static int IndexOf(
	Array array,
	Object value
)

Parameters

array
Type: System..::..Array
The one-dimensional Array to search.
value
Type: System..::..Object
The object to locate in array.

Return Value

Type: System..::..Int32
The index of the first occurrence of value within the entire array, if found; otherwise, the lower bound of the array minus 1.

ExceptionCondition
ArgumentNullException

array is nullNothingnullptrunita null reference (Nothing in Visual Basic).

RankException

array is multidimensional.

The one-dimensional Array is searched forward starting at the first element and ending at the last element.

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 the Length of array.

Show: