System.Text.StringBuilder.Length Property

Gets or sets the length of the current System.Text.StringBuilder object.

Syntax

public int Length { get; set; }

Value

A int containing the length of the current instance.

Exceptions

TypeReason
ArgumentOutOfRangeExceptionThe value specified for a set operation is less than 0.

Remarks

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

If the specified length is less than the current length, the current System.Text.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 System.Text.StringBuilder object is padded with the Unicode NULL character (U+0000).

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

Requirements

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