System.Collections.Generic.List<T>.Capacity Property
Gets or sets the number of elements the current instance can contain.

Syntax

public int Capacity { get; set; }

Value

A int containing the number of elements the current instance can contain.

Exceptions

TypeReason
ArgumentOutOfRangeExceptionAttempt to set the capacity to a value less than List<T>.Count.

Remarks

This property is read/write.

List<T>.Capacity is the number of elements that the list is capable of storing without needing to be extended. List<T>.Count is the number of elements that are actually in the list.

List<T>.Capacity is always greater than or equal to List<T>.Count. When List<T>.Count exceeds List<T>.Capacity while adding elements, the capacity is increased.

The capacity can be decreased by calling List<T>.TrimToSize or by setting the List<T>.Capacity property explicitly.

Requirements

Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0