StringBuilder

Stringbuilder is an internal class provided by C# that helps us to improve string manipulation functions. To explain the idea, we will be executing a for loop from 0 to 100 and will be concatenating the resultant output in each loop with the letter a. Internally, a string builder uses a buffer to modify the string value instead of allocating memory on every string manipulation. The following code example shows how we can use string builder for string manipulation operations:

StringBuilder sb = new StringBuilder(string.Empty);
for (int z = 0; z < 100; z++)
{
sb.Append("a");
}

In the preceding code, we are declaring a StringBuilder object, sb, and are appending its value with a in the loop. Internally, instead of allocating memory on every concatenation, StringBuilder will use an internal buffer to manage these operations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.5