Array.IndexOf Method (Array, Object, Int32)
Searches for the specified object and returns the index of the first occurrence within the range of elements in the one-dimensional Array that extends from the specified index to the last element.
Assembly: mscorlib (in mscorlib.dll)
- Type: System.Object
The object to locate in array.
- Type: System.Int32
The starting index of the search. 0 (zero) is valid in an empty array.
Return ValueType: System.Int32
The index of the first occurrence of value within the range of elements in array that extends from startIndex to the last element, if found; otherwise, the lower bound of the array minus 1.
The one-dimensional Array is searched forward starting at startIndex 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 number of elements from startIndex to the end of array.
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.
.NET FrameworkSupported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.