-
Notifications
You must be signed in to change notification settings - Fork 36
M_CodeJam_Collections_ArrayExtensions_BinarySearch__1_2
Searches an entire one-dimensional sorted Array for a specific element, using the IComparable(T) generic interface implemented by each element of the Array and by the specified object.
Namespace: CodeJam.Collections
Assembly: CodeJam (in CodeJam.dll) Version: 2.1.0.0
C#
public static int BinarySearch<T>(
this T[] array,
T value
)
VB
<ExtensionAttribute>
Public Shared Function BinarySearch(Of T) (
array As T(),
value As T
) As Integer
F#
[<ExtensionAttribute>]
static member BinarySearch :
array : 'T[] *
value : 'T -> int
- array
- Type: T[]
The sorted one-dimensional, zero-based Array to search. - value
- Type: T
The object to search for.
- T
- The type of the elements of the array.
Type: Int32
The index of the specified value in the specified array, if value is found. If value is not found and value is less than one or more elements in array, a negative number which is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than any of the elements in array, a negative number which is the bitwise complement of (the index of the last element plus 1).
In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exception | Condition |
---|---|
ArgumentNullException | array is null. |
InvalidOperationException | value does not implement the IComparable(T) generic interface, and the search encounters an element that does not implement the IComparable(T) generic interface. |
ArrayExtensions Class
BinarySearch Overload
CodeJam.Collections Namespace