How to find the MaxCapacity of a StringBuilder in C# Last Updated : 28 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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.MaxValue. However, this value is implementation-specific and might be different in other or later implementations. You can explicitly set the maximum capacity of a StringBuilder object by calling the StringBuilder(Int32, Int32) constructor. Example: csharp // C# program to demonstrate // the MaxCapacity Property using System; using System.Text; class GFG { // Main Method public static void Main(String[] args) { // Create a StringBuilder object // with a String passed as parameter StringBuilder str1 = new StringBuilder("GeeksforGeeks"); // printing the MaxCapacity of str1 Console.WriteLine("Maximum Capacity of str1 is: " + str1.MaxCapacity); // Create a StringBuilder object StringBuilder str2 = new StringBuilder(); // printing the MaxCapacity of str2 Console.WriteLine("Maximum Capacity of str2 is: " + str2.MaxCapacity); } } Output: Maximum Capacity of str1 is: 2147483647 Maximum Capacity of str2 is: 2147483647 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.maxcapacity?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article How to find the MaxCapacity of a StringBuilder in C# K Kirti_Mangal 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 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 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 immutabl 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 StringBuilder.EnsureCapacity() Method in C# The EnsureCapacity(Int32) method of StringBuilder class helps us to ensures the capacity is at least equal to the specified value that is passed as the parameter to the method. If the current capacity is less than the capacity parameter, memory for this instance is reallocated to hold at least capac 2 min read Like