Length Property
Collapse the table of content
Expand the table of content

StringBuilder.Length Property

 

Gets or sets the length of the current StringBuilder object.

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

member Length : int with get, set

Property Value

Type: System.Int32

The length of this instance.

Exception Condition
ArgumentOutOfRangeException

The value specified for a set operation is less than zero or greater than MaxCapacity.

The length of a StringBuilder object is defined by its number of Char objects.

Like theString.Length property, the Length property indicates the length of the current string object. Unlike the String.Length property, which is read-only, the Length property allows you to modify the length of the string stored to the StringBuilder object.

If the specified length is less than the current length, the current StringBuilder object is truncated to the specified length. If the specified length is greater than the current length, the end of the string value of the current StringBuilder object is padded with the Unicode NULL character (U+0000).

If the specified length is greater than the current capacity, Capacity increases so that it is greater than or equal to the specified length.

The following example demonstrates the Length property.

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

Universal Windows Platform
Available since 4.5
.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:
© 2016 Microsoft