Users Online

· Guests Online: 66

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate StringBuilder

C# Program to Demonstrate StringBuilder

 

 

This is a C# Program to illustrate stringbuilder.

Problem Description

This C# Program Illustrates StringBuilder.

Problem Solution

Here ToString method is used on the StringBuilder type. This method is used to convert a StringBuilder’s character buffer into an actual string reference.

Program/Source Code

Here is source code of the C# Program to Illustrate StringBuilder. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Illustrate StringBuilder
 */
using System;
using System.Text;
class Program
{
    static void Main()
    {
        StringBuilder bd = new StringBuilder();
        bd.Append("1 ");
        bd.Append("2 ");
        bd.Append("3 ");
        for (int i = 0; i < 5; i++)
        {
            bd.Append("z ");
        }
        string result = bd.ToString();
        Console.WriteLine(result);
        Console.ReadLine();
    }
}
Program Explanation

This C# program is used to illustrate StringBuilder. The Append() method is used to append a copy of the specified string to this instance. Using for loop append the value of ‘z’ character value to the remaining values in for loop.

 

ToString() method is used on the StringBuilder type. This method is used to convert a StringBuilder’s character buffer into an actual string reference.

Runtime Test Cases
 
1 2 3 z z z z z

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.68 seconds
10,844,565 unique visits