Partager via


Array.BinarySearch Method (Array, Object, IComparer)

Searches an entire one-dimensional sorted array for a specified value, using the specified IComparer interface.

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

Syntax

public static int BinarySearch (
         Array array,
         Object value,
         IComparer comparer
)

Parameters

  • array
    The one-dimensional array you want to search.
  • value
    The object you want to search for.
  • comparer
    The IComparer implementation you want to use when comparing elements. If this parameter is null, the Array.BinarySearch method uses the IComparable implementation of each object in the array.

Return Value

The index number of the specified value in the specified array, if the value is found in the array.

-or-

A negative number, which is the bitwise complement of the index number of the first object that is larger than the specified value, if that value is not found and it is less than at least one of the objects in the array.

-or-

A negative number, which is the bitwise complement of the index number of the last object in the array plus 1, if the specified value is not found and it is greater than at least one of the objects in the array.

Version Information

Available in the .NET Micro Framework versions 2.0, 2.5, 3.0, 4.0, 4.1, and 4.2.

See Also

Reference

Array Class
Array Members
System Namespace