This documentation is archived and is not being maintained.

ArrayList.Sort Method (Int32, Int32, IComparer)

Sorts the elements in a range of elements in ArrayList using the specified comparer.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

abstract Sort : 
        index:int * 
        count:int * 
        comparer:IComparer -> unit 
override Sort : 
        index:int * 
        count:int * 
        comparer:IComparer -> unit 


Type: System.Int32
The zero-based starting index of the range to sort.
Type: System.Int32
The length of the range to sort.
Type: System.Collections.IComparer
The IComparer implementation to use when comparing elements.
A null reference (Nothing in Visual Basic) to use the IComparable implementation of each element.


index is less than zero.


count is less than zero.


index and count do not specify a valid range in the ArrayList.


The ArrayList is read-only.


An error occurred while comparing two elements.

If comparer is set to a null reference (Nothing in Visual Basic), 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.

The following code example shows how to sort the values in a range of elements in an ArrayList using the default comparer and a custom comparer that reverses the sort order.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.