Export (0) Print
Expand All

StringBuilder.Capacity Property

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)

member Capacity : int with get, set

Property Value

Type: System.Int32
The maximum number of characters that can be contained in the memory allocated by the current instance. Its value can range from Length to MaxCapacity.

ExceptionCondition
ArgumentOutOfRangeException

The value specified for a set operation is less than the current length of this instance.

-or-

The value specified for a set operation is greater than the maximum capacity.

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.

The following example demonstrates the Capacity property.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft