System.Collections.Generic.List<T>.Sort Method
Sorts the elements in the list using the default comparer.

Syntax

public void Sort ()

Exceptions

TypeReason
InvalidOperationExceptionThe default comparer cannot find a IComparable<T> or IComparable implementation for type T.

Remarks

This method uses the default comparer for type T to determine the order of list elements. If there is no default comparer, then the method throws InvalidOperationException. The default comparer for a given element type T is defined in the Description section of this (class List<T>) specification.

At worst, this operation is O(n2), where n is the number of elements to sort. On average it's O(n log n).

Requirements

Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0