Sets the capacity to the actual number of elements in the ArrayList.
Type Reason NotSupportedException The 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.