StringBuilder.Chars[] Property in C# Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report StringBuilder.Chars[Int32] Property is used to get or set the character at the specified character position in this instance. Syntax: public char this[int index] { get; set; } Here, the index is the position of the character. Property Value: This property returns the Unicode character at position index. Exceptions: ArgumentOutOfRangeException: If the index is outside the bounds of this instance while setting a character. IndexOutOfRangeException: If the index is outside the bounds of this instance while getting a character. Below programs illustrate the use of the above-discussed property: Example 1: csharp // C# program demonstrate // the Chars[Int32] Property using System; using System.Text; class GFG { // Main Method public static void Main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("GeeksforGeeks"); // print string Console.WriteLine("String is " + str.ToString()); // loop through string // and print every Character for (int i = 0; i < str.Length; i++) { // get char at position i char ch = str[i]; // print char Console.WriteLine("Char at position " + i + " is " + ch); } } } Output: String is GeeksforGeeks Char at position 0 is G Char at position 1 is e Char at position 2 is e Char at position 3 is k Char at position 4 is s Char at position 5 is f Char at position 6 is o Char at position 7 is r Char at position 8 is G Char at position 9 is e Char at position 10 is e Char at position 11 is k Char at position 12 is s Example 2: csharp // C# program demonstrate // the Chars[Int32] Property using System; using System.Text; class GFG { // Main Method public static void Main(String[] args) { // create a StringBuilder object StringBuilder str = new StringBuilder(); // add the String to StringBuilder Object str.Append("Geek"); // get char at position 1 char ch = str[1]; // print the result Console.WriteLine("StringBuilder Object" + " contains = " + str); Console.WriteLine("Character at Position 1" + " in StringBuilder = " + ch); } } Output: StringBuilder Object contains = Geek Character at Position 1 in StringBuilder = e Reference: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.chars?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article How to remove all characters from StringBuilder in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-StringBuilder-Class Similar Reads 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 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 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.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# | Check if two StringBuilder objects are Equal StringBuilder.Equals Method is used to check whether this instance is equal to a specified object. Syntax: public bool Equals (System.Text.StringBuilder sb); Here, sb is an object to compare with this instance, or null. Return Value: It will return true if this instance and sb have an equal string, 2 min read Like