2
Reply

StringBuilder/string

Maha

Maha

Jul 31 2013 1:50 PM
820
When s2 data type is StringBuilder no need for ToString() method but when s3 data type is string there is need for ToString() method. Is there any explanation for this? Problem is highlighted.

using System;
using System.Text;

class Program
{
static void Main(string[] args)
{
string s1 = "string1 ";

StringBuilder s2 = new StringBuilder("string1 ").Append(s1);

Console.WriteLine(s2);//string1 string1

string s3 = new StringBuilder("string1 ").Append(s1).ToString();

Console.WriteLine(s3);//string1 string1

Console.ReadKey();
}
}


Answers (2)