The sorting algorithm (QuickSort) is based on the predictable implementation of IComparer. After several tens of layers of indirection in BCL, you find yourself in this method:
public void Sort(T[] keys, int index, int length, IComparer<T> comparer)
{
try
{
...
ArraySortHelper<T>.QuickSort(keys, index, index + (length - 1), comparer);
}
catch (IndexOutOfRangeException)
{
...
throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", values));
}
}
Going a little further into the QuickSort implementation, you see this code:
while (comparer.Compare(keys[a], y) < 0)
{
a++;
}
while (comparer.Compare(y, keys[b]) < 0)
{
b--;
}
, IComparer Quicksort IndexOutOfRangeException, n ArgumentException.
IComparer
class Comparer: IComparer<int>
{
public int Compare(int x, int y)
{
return -1;
}
}
, , , , IComparer , :
, , , , .