System.Collections.ArrayList.Sort Method

Sorts the elements in the entire ArrayList.


public virtual void Sort ()


InvalidCastExceptionOne or more elements in the current instance do not implement the IComparable interface.
NotSupportedExceptionThe current instance is read-only.


This method uses Array.Sort(Array), 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 ArrayList.Count; in the worst case it is an O(n^2) operation.


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