System.Collections.SortedList.TrimToSize Method

Sets the capacity to the actual number of elements in a SortedList object.

Syntax

public virtual void TrimToSize ()

Remarks

This method can be used to minimize a collection's memory overhead if no new elements will be added to the collection.

To reset a SortedList object to its initial state, call the SortedList.Clear method before calling SortedList.TrimToSize. Trimming an empty SortedList sets the capacity of the SortedList to the default capacity.

This method is an O(n) operation, where n is SortedList.Count.

Requirements

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