SortedList.TrimToSize Method ()


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

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

abstract TrimToSize : unit -> unit
override TrimToSize : unit -> unit

Exception Condition

The SortedList object is read-only.


The SortedList has a fixed size.

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 Clear method before calling 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 Count.

The following code example shows how to trim the unused portions of a SortedList object and how to clear its values.

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