System.Collections.ArrayList.IListWrapper.BinarySearch C# (CSharp) Метод

BinarySearch() публичный Метод

public BinarySearch ( int index, int count, Object value, IComparer comparer ) : int
index int
count int
value Object
comparer IComparer
Результат int
            public override int BinarySearch(int index, int count, Object value, IComparer comparer)
            {
                if (index < 0 || count < 0)
                    throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
                if (Count - index < count)
                    throw new ArgumentException(SR.Argument_InvalidOffLen);
                Contract.EndContractBlock();
                if (comparer == null)
                    comparer = Comparer.Default;

                int lo = index;
                int hi = index + count - 1;
                int mid;
                while (lo <= hi)
                {
                    mid = (lo + hi) / 2;
                    int r = comparer.Compare(value, _list[mid]);
                    if (r == 0)
                        return mid;
                    if (r < 0)
                        hi = mid - 1;
                    else
                        lo = mid + 1;
                }
                // return bitwise complement of the first element greater than value.
                // Since hi is less than lo now, ~lo is the correct item.
                return ~lo;
            }