StringBuilder class

StringBuilder from System.Text namespace is a mutable string.

The following code appends strings to StringBuilder.


using System;
using System.Text;
class Sample
{
    public static void Main()
    {
        StringBuilder sb = new StringBuilder();
        string[] strs = new string[] { "a", "v", "c" };
        foreach (string s in strs)
        {
            sb.Append(s);
        }
        Console.WriteLine(sb);
    }
}

The output:


avc

Using Append method from StringBuilder is more efficient than using + to add strings together.

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.