How to create the StringBuilder in C# Last Updated : 08 Apr, 2019 Comments Improve Suggest changes Like Article Like Report StringBuilder() constructor is used to initialize a new instance of the StringBuilder class which will be empty and will have the default initial capacity. StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutable but StringBuilder is the mutable string type. It will not create a new modified instance of the current string object but do the modifications in the existing string object. Syntax: public StringBuilder (); Example: csharp // C# Program to illustrate how // to create a StringBuilder using System; using System.Text; using System.Collections; class Geeks { // Main Method public static void Main(String[] args) { // sb is the StringBuilder object // StringBuilder() is the constructor // used to initializes a new // instance of the StringBuilder class StringBuilder sb = new StringBuilder(); // Capacity property is used to get // maximum number of characters that // can be contained in the memory // allocated by the current instance Console.WriteLine(sb.Capacity); } } Output: 16 Here 16 is the default capacity. Note: Using this constructor will set the string value of the current instance to String.Empty. Capacity is set to the implementation-specific default capacity. Here it is 16. Comment More infoAdvertise with us Next Article How to create the StringBuilder in C# ankita_saini Follow Improve Article Tags : C# CSharp-StringBuilder-Class Similar Reads How to find the Capacity of a StringBuilder in C# StringBuilder.Capacity Property is used to get or set the maximum number of characters that can be contained in the memory allocated by the current instance. Syntax: public int Capacity { get; set; }Return Value: This property will return the maximum number of characters that can be contained in the 2 min read How to create a StringCollection in C# StringCollection() constructor is used to initializing a new instance of the StringCollection class. StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace 2 min read How to create a StringDictionary in C# StringDictionary() constructor is used to initialize a new instance of the StringDictionary class which will be empty and will have the default initial capacity. StringDictionary is a specialized collection. This class comes under the System.Collections.Specialized namespace. It only allows string k 2 min read How to find the length of the StringBuilder in C# StringBuilder.Length Property is used to get or set the length of the current StringBuilder object. Syntax: public int Length { get; set; } It returns the length of the current instance. Exception: This property will give ArgumentOutOfRangeException if the value specified for a set operation is less 2 min read How to remove all characters from StringBuilder in C# StringBuilder.Clear Method is used to remove all the characters from the current StringBuilder instance. Syntax: public System.Text.StringBuilder Clear (); It returns an StringBuilder object whose length will be zero. Note: Clear is a convenience method that is equivalent to setting the Length prope 1 min read How to Compare Strings in C#? A string is a collection of characters and is used to store plain text. Unlike C or C++, a string in C# is not terminated with a null character. The maximum size of a string object depends on the internal architecture of the system. A variable declared followed by "string" is actually an object of s 13 min read How to find the MaxCapacity of a StringBuilder in C# StringBuilder.MaxCapacity Property is used to get the maximum capacity of this instance. Syntax: public int MaxCapacity { get; } Property Value: It returns the maximum number of characters of type System.Int32 this instance can hold. Note: The maximum capacity for this implementation is Int32.MaxVal 1 min read StringBuilder.ToString Method in C# This method is used to converts the value of this instance to a String. A new String object is created and initialized to get the character sequence from this StringBuilder object and then String is returned by ToString(). Subsequent changes to this sequence contained by Object do not affect the con 2 min read C# String vs StringBuilder StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutable but StringBuilder is the mutable string type. It will not create a new modified instance of the current string object but do the modifications in the exis 3 min read StringBuilder.CopyTo Method in C# This method is used to copy the characters from a specified segment of this instance to a specified segment of a destination Char array. Syntax: public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count); Parameters: sourceIndex: It is the starting position in this ins 2 min read Like