Array.IndexOf Method (Array, Object, Int32, Int32)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Searches for the specified object and returns the index of the first occurrence within the range of elements in the one-dimensional Array that starts at the specified index and contains the specified number of elements.
Assembly: mscorlib (in mscorlib.dll)
Public Shared Function IndexOf ( _ array As Array, _ value As Object, _ startIndex As Integer, _ count As Integer _ ) As Integer
public static int IndexOf( Array array, Object value, int startIndex, int count )
The object to locate in array.
The starting index of the search.
The number of elements in the section to search.
The index of the first occurrence of value within the range of elements in array that starts at startIndex and contains the number of elements specified in count, if found; otherwise, the lower bound of the array minus 1.
array is nullNothingnullptra null reference (Nothing in Visual Basic).
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 forward starting at startIndex and ending at startIndex plus count minus 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 valueObject itself.
Windows Phone OS
Supported in: 8.1, 8.0, 7.1, 7.0