Capacity Property

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Namespace:  System.Text
Assembly:  mscorlib (in mscorlib.dll)

public int Capacity { get; set; }

Property Value

Type: System..::..Int32
The maximum number of characters that can be contained in the memory allocated by the current instance.

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

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

Show: