How to find the length of the StringBuilder in C# Last Updated : 28 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 than zero or greater than MaxCapacity. Below programs illustrate the use of the above-discussed property: Example 1: csharp // C# program to demonstrate // the Length() 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 str = new StringBuilder("WelcomeGeeks"); // print string Console.WriteLine("String = " + str.ToString()); // get length of StringBuilder object int length = str.Length; // print length Console.WriteLine("length of String = " + length); } } Output: String = WelcomeGeeks length of String = 12 Example 2: csharp // C# program to demonstrate // the Length() Property using System; using System.Text; class GFG { public static void Main(String[] args) { // create a StringBuilder object // with a String passed as parameter StringBuilder str = new StringBuilder("India is Great"); // print string Console.WriteLine("String = " + str.ToString()); // get length of StringBuilder object int length = str.Length; // print length Console.WriteLine("length of String = " + length); } } Output: String = India is Great length of String = 14 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.length?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article How to find the length of the StringBuilder in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-StringBuilder-Class Similar Reads 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 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 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 find the length of an Array in C# Array.Length Property is used to get the total number of elements in all the dimensions of the Array. Basically, the length of an array is the total number of the elements which is contained by all the dimensions of that array. Syntax: public int Length { get; } Property Value: This property returns 3 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 Like