ArrayList.Sort Method (Int32, Int32, IComparer)
Sorts the elements in a range of elements in ArrayList using the specified comparer.
Assembly: mscorlib (in mscorlib.dll)
abstract Sort : index:int * count:int * comparer:IComparer -> unit override Sort : index:int * count:int * comparer:IComparer -> unit
Parameters
- index
-
Type:
System.Int32
The zero-based starting index of the range to sort.
- count
-
Type:
System.Int32
The length of the range to sort.
- comparer
-
Type:
System.Collections.IComparer
The IComparer implementation to use when comparing elements.
-or-
A null reference (Nothing in Visual Basic) to use the IComparable implementation of each element.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | index is less than zero. -or- count is less than zero. |
| ArgumentException | index and count do not specify a valid range in the ArrayList. |
| NotSupportedException | The ArrayList is read-only. |
| InvalidOperationException | An error occurred while comparing two elements. |
If comparer is set to null, this method performs a comparison sort (also called an unstable sort); that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal. To perform a stable sort, you must implement a custom IComparer interface.
On average, this method is an O(n log n) operation, where n is count; in the worst case it is an O(n^2) operation.
Available since 10
.NET Framework
Available since 1.1