Mono Class Library: System.Text Namespace

System.Text.StringBuilder Class

Represents a mutable string of characters. [Edit]

See Also: StringBuilder Members

[System.Runtime.InteropServices.ComVisible(true)]
public sealed class StringBuilder : System.Runtime.Serialization.ISerializable

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

This class represents string-like objects that are mutable. After a System.Text.StringBuilder object has been created, it can be directly modified by removing, replacing, or inserting characters. This contrasts the string class, which represents an immutable string of characters.

The StringBuilder.Capacity of an instance of the System.Text.StringBuilder class is the maximum number of characters it can hold in the currently allocated space. The System.Text.StringBuilder will dynamically allocate more space when it is required.

Unlike most types in the Base Class Library, the arguments to System.Text.StringBuilder members are assumed to be passed as in / out arguments (passed by reference).

Note: Normally arguments are in arguments (passed by value) unless explicitly declared as out or in / out.

Note:

An instance of string is said to be "immutable" because its value cannot be modified once it has been created. Methods on string that appear to modify a string instance actually return a new instance containing the modification. The System.Text.StringBuilder class provides methods that actually modify the contents of a string-like object.

Relational operators only perform reference comparisons (unless overloaded by a particular language compiler). Despite this restriction, relational operators can be used to compare string objects that are assigned literal values. Their values are immutable and can't change, so a reference comparison is sufficient. Because System.Text.StringBuilder instances are mutable, they should not be compared with relational operators.

For performance reasons a System.Text.StringBuilder might allocate more memory than needed. The amount of memory allocated is implementation specific.

[Edit]

Requirements

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