NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Array.BinarySearch (Array, Object)

Searches a one-dimensional Array for a specific element, using the IComparable interface implemented by each element of the Array and by the specified Object.

[Visual Basic]
Overloads Public Shared Function BinarySearch( _
   ByVal array As Array, _
   ByVal value As Object _
) As Integer
[C#]
public static int BinarySearch(
   Array array,
   object value
);
[C++]
public: static int BinarySearch(
   Array* array,
   Object* value
);
[JScript]
public static function BinarySearch(
   array : Array,
   value : Object
) : int;

Parameters

array
The one-dimensional Array to search.
value
The Object to search for.

Return Value

The index of the value in the Array, if value is found. Otherwise, a negative number, which is the bitwise complement of the index of the first element that is larger than value.

Exceptions

Exception Type Condition
ArgumentNullException array is a null reference (in Visual Basic Nothing).
RankException array is multidimensional.
ArgumentException Neither value nor the elements of array implement the IComparable interface.

-or-

value is not of the same type as the elements of array.

Remarks

value and each element of array must implement the IComparable interface, which is used for comparisons.

If array is not already sorted according to the IComparable interface, the result may be incorrect.

a null reference (Nothing) can always be compared with any other type; therefore, comparisons with a null reference (Nothing) will not generate an exception. When sorting, a null reference (Nothing) is considered to be less than any other object.

The bitwise complement operator (~) can be applied to a negative result to produce the index of the first element (if any) that is larger than the specified search value.

See Also

Array Class | Array Members | System Namespace | Array.BinarySearch Overload List | IComparable | Sort