If the Array does not contain the specified value, the method returns a negative integer. You can apply the bitwise complement operator (~) to the negative result (in Visual Basic, Xor the negative result with -1) to produce an index. If this index is greater than or equal to the size of the array, there are no elements larger than value in the array. Otherwise, it is the index of the first element that is larger than value.
Either value or every element of array must implement the IComparable<(Of <(T>)>) generic interface, which is used for comparisons. The elements of array must already be sorted in increasing value according to the sort order defined by the IComparable<(Of <(T>)>) implementation; otherwise, the result might be incorrect.
Duplicate elements are allowed. If the Array contains more than one element equal to value, the method returns the index of only one of the occurrences, and not necessarily the first one.
nullNothingnullptra null reference (Nothing in Visual Basic) can always be compared with any other reference type; therefore, comparisons with nullNothingnullptra null reference (Nothing in Visual Basic) do not generate an exception. When sorting, nullNothingnullptra null reference (Nothing in Visual Basic) is considered to be less than any other object.
Note: |
|---|
For every element tested,
value is passed to the appropriate IComparable<(Of <(T>)>) implementation, even if value is nullNothingnullptra null reference (Nothing in Visual Basic). That is, the IComparable<(Of <(T>)>) implementation determines how a given element compares to nullNothingnullptra null reference (Nothing in Visual Basic).
|
This method is an O(log n) operation, where n is the Length of array.