Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Array.IList.IndexOf Method

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

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

int IList.IndexOf(
	Object value
)

Parameters

value
Type: System.Object
The object to locate in the current 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.

Implements

IList.IndexOf(Object)

ExceptionCondition
RankException

The current 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 Length.

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.

Silverlight

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft