| ArrayListBinarySearch Method (Int32, Int32, Object, IComparer) | 
Searches a range of elements in the sorted 
ArrayList for an element using the specified comparer and returns the zero-based index of the element.
 
Namespace: System.CollectionsAssembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
 Syntax
Syntaxpublic virtual int BinarySearch(
	int index,
	int count,
	Object value,
	IComparer comparer
)
Parameters
- index
- Type: SystemInt32
 The zero-based starting index of the range to search.
- count
- Type: SystemInt32
 The length of the range to search.
- value
- Type: SystemObject
 The Object to locate. The value can be null.
- comparer
- Type: System.CollectionsIComparer
 The IComparer implementation to use when comparing elements.-or- null to use the default comparer that is the IComparable implementation of each element.
Return Value
Type: 
Int32The zero-based index of 
value in the sorted 
ArrayList, if 
value is found; otherwise, a negative number, which is the bitwise complement of the index of the next element that is larger than 
value or, if there is no larger element, the bitwise complement of 
Count.
 Exceptions
Exceptions| Exception | Condition | 
|---|
| ArgumentException | index and count do not denote a valid range in the ArrayList.-or- comparer is null and neither value nor the elements of ArrayList implement the IComparable interface. | 
| InvalidOperationException | comparer is null and value is not of the same type as the elements of the ArrayList. | 
| ArgumentOutOfRangeException | index is less than zero.-or- count is less than zero. | 
 See Also
See Also