System.Collections.ArrayList.TrimToSize Method

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


public virtual void TrimToSize ()


NotSupportedExceptionThe current instance is read-only or 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 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.


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