How to create the StringBuilder in C#
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:
using System;
using System.Text;
using System.Collections;
class Geeks {
public static void Main(String[] args)
{
StringBuilder sb = new StringBuilder();
Console.WriteLine(sb.Capacity);
}
}
|
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.
Last Updated :
08 Apr, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...