How to append string to existing string using StringBuilder in C#

2 Answers

0 votes
using System;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder("string");

            sb.Append(" builder");
            Console.WriteLine(sb); // string builder
        }
    }
}

/*
run:
  
string builder

*/


answered Feb 24, 2015 by avibootz
0 votes
using System;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder("numbers: ");
            
            for (int i = 1; i <= 10; i++)
            {
                sb.Append(i).Append(" ");
            }
            Console.WriteLine(sb); // numbers: 1 2 3 4 5 6 7 8 9 10
        }
    }
}

/*
run:
 
numbers: 1 2 3 4 5 6 7 8 9 10

*/ 


answered Feb 24, 2015 by avibootz

Related questions

1 answer 177 views
1 answer 131 views
1 answer 207 views
1 answer 100 views
1 answer 139 views
1 answer 130 views
...