Searches the current instance for the specified object using the specified IComparer implementation.
- value
- The object for which to search.
- comparer
- The IComparer implementation to use when comparing elements. Specify null to use the IComparable implementation of each element.
A int that specifies the results of the search as follows:
Return Value Description The index of value in the current instance. value was found. The bitwise complement of the index of the first element that is greater than value. value was not found, and at least one element in the current instance is greater than value. The bitwise complement of the ArrayList.Count of the current instance. value was not found, and value is greater than all elements in the current instance. Note: If value is not found and the current instance is already sorted, the bitwise complement of the return value indicates the index in the current instance where value would be found.
Type Reason ArgumentException comparer is null, and value is not assignment-compatible with at least one element in the current instance. InvalidOperationException comparer is null, and both value and at least one element involved in the search in the current instance do not implement the IComparable interface.
This method performs a binary search.
Note: A null reference can be compared with any type; therefore, comparisons with a null reference do not generate exceptions. A null reference evaluates to less than any non-null object, or equal to another null reference, when the two are compared.Operation
As described above.This method uses Array.BinarySearch(Array, object) to search for value.
value is compared to elements in a binary search of the current instance until an element with a value greater than or equal to value is found. If comparer is null, the IComparable implementation of the element being compared -- or of value if the element being compared does not implement the interface -- is used to make the comparison. If value does not implement the IComparable interface and is compared to an element that does not implement the interface, InvalidOperationException is thrown. If the current instance is not already sorted, correct results are not guaranteed.
Note: For the default implementation, this method is an O(log2n) operation where n is equal to the ArrayList.Count of the current instance.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0