How to find the MaxCapacity of a StringBuilder in C#
Last Updated :
28 Jan, 2019
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:
using System;
using System.Text;
class GFG {
public static void Main(String[] args)
{
StringBuilder str1 =
new StringBuilder( "GeeksforGeeks" );
Console.WriteLine( "Maximum Capacity of str1 is: "
+ str1.MaxCapacity);
StringBuilder str2 = new StringBuilder();
Console.WriteLine( "Maximum Capacity of str2 is: "
+ str2.MaxCapacity);
}
}
|
Output:
Maximum Capacity of str1 is: 2147483647
Maximum Capacity of str2 is: 2147483647
Reference:
Share your thoughts in the comments
Please Login to comment...