StringBuilder.EnsureCapacity Method (Int32)

 

Ensures that the capacity of this instance of StringBuilder is at least the specified value.

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

member EnsureCapacity : 
        capacity:int -> int

Parameters

capacity
Type: System.Int32

The minimum capacity to ensure.

Return Value

Type: System.Int32

The new capacity of this instance.

Exception Condition
ArgumentOutOfRangeException

capacity is less than zero.

-or-

Enlarging the value of this instance would exceed MaxCapacity.

If the current capacity is less than the capacity parameter, memory for this instance is reallocated to hold at least capacity number of characters; otherwise, no memory is changed.

The following example demonstrates the EnsureCapacity method.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: