ArrayList.Sort Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Sorts the elements in the entire ArrayList.

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

abstract Sort : unit -> unit
override Sort : unit -> unit

Exception Condition
NotSupportedException

The ArrayList is read-only.

This method uses Array.Sort, which uses the QuickSort algorithm. The QuickSort algorithm is a comparison sort (also called an unstable sort), which means that a "less than or equal to" comparison operation determines which of two elements should occur first in the final sorted list. However, if two elements are equal, their original 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 to use with the other overloads of this method.

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 an ArrayList.

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

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: