System.Text.StringBuilder.Capacity Property

Gets or sets the maximum number of characters that can be contained in the memory allocated by the current instance.

Syntax

public int Capacity { get; set; }

Value

A int containing the maximum number of characters that can be contained in the memory allocated by the current instance.

Exceptions

TypeReason
ArgumentExceptionThe value specified for a set operation is less than StringBuilder.Length.

Remarks

StringBuilder.Capacity does not affect the string value of the current instance. StringBuilder.Capacity can be decreased as long as it is not less than StringBuilder.Length.

The System.Text.StringBuilder dynamically allocates more space when required and increases StringBuilder.Capacity accordingly. For performance reasons, a System.Text.StringBuilder might allocate more memory than needed. The amount of memory allocated is implementation-specific.

Requirements

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