System.Collections.ArrayList.TrimToSize Method

Sets the capacity to the actual number of elements in the ArrayList.

Syntax

public virtual void TrimToSize ()

Exceptions

TypeReason
NotSupportedExceptionThe current instance is read-only or has a fixed size.

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 ArrayList to its initial state, call the ArrayList.Clear method before calling ArrayList.TrimToSize. Trimming an empty ArrayList sets the capacity of the ArrayList to the default capacity.

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

Requirements

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