Mono Class Library: System.Collections.ArrayList Overview | Members

System.Collections.ArrayList.Sort Method

Sorts the elements in the specified range of the current instance using the specified IComparer implementation.

public virtual void Sort (int index, int count, IComparer comparer)

Parameters

index
A int that specifies the zero-based index at which sorting starts. This value is between 0 and the ArrayList.Count of the current instance minus count , inclusive.
count
A int that specifies the number of elements to sort. This value is between 0 and the ArrayList.Count of the current instance minus index , inclusive.
comparer
The IComparer implementation to use when comparing elements. Specify null to use the IComparable implementation of each element in the current instance.

Exceptions

TypeReason
ArgumentOutOfRangeException

index < 0.

-or-

count < 0.

ArgumentExceptionArrayList.Count of the current instance - index < count.
InvalidCastExceptioncomparer is null, and one or more elements in the current instance do not implement the IComparable interface.
NotSupportedExceptionThe current instance is read-only.
InvalidOperationExceptioncomparer is null, and one or more elements in the current instance do not implement the IComparable interface.

Remarks

Operation
As described above.

If comparer is null, the IComparable implementation of each element in the current instance is used to make the sorting comparisons. If the sort is not successfully completed, the results are unspecified.

Note: For the default implementation, this method uses Array.Sort(Array), which uses the Quicksort algorithm. This is an O(n log2n) operation, where n is the number of elements to sort.

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0