Пример #1
0
        public static void Sort <T>(T[] array, int index, int length, System.Collections.Generic.IComparer <T>?comparer)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (index < 0)
            {
                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
            }
            if (length < 0)
            {
                ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
            }
            if (array.Length - index < length)
            {
                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
            }

            if (length > 1)
            {
#if CORECLR
                if (comparer == null || comparer == Comparer <T> .Default)
                {
                    if (TrySZSort(array, null, index, index + length - 1))
                    {
                        return;
                    }
                }
#endif

                ArraySortHelper <T> .Default.Sort(array, index, length, comparer);
            }
        }
Пример #2
0
        public static int BinarySearch <T>(T[] array, int index, int length, T value, System.Collections.Generic.IComparer <T>?comparer)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (index < 0)
            {
                ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
            }
            if (length < 0)
            {
                ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
            }

            if (array.Length - index < length)
            {
                ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
            }

            return(ArraySortHelper <T> .Default.BinarySearch(array, index, length, value, comparer));
        }