can any one explain with examples
Related Discussion: Most efficient way to concatenate strings?
A string object is immutable, once created, it cannot be changed
string str;
//new string object constructed. str= new string("string1");
str="string1";
//again new object will be constructed str=new string("string1string2");
str=str+"string2"
since a new object is created for every assignment, there is an overhead.
However, string builder class provides an efficient way to repeatedly append bits of string to already constructed object.
StringBuilder str=new StringBuilder();
str.Append("string1");
str.Append("string2");
The performance difference will be too small to compare on fewer assignment and concatenation operation, but there is significance performance gain by switching from string to stringbuilder if we have more of these string operations.