Hi,
Please read carefully before assuming that this is the same old
question about string concatenation in C#!
It is well-known that the following concatenation produces multiple
immutable String objects for each statement:
String a = "a";
a += "b";
a += "c";
a += "d";
However, I have not seen any source say whether or not the following
statement creates a new String object for each concatenation (i.e.,
each "+" sign):
String b = a + "b" + "c" + "d";
In other words: if the concatenation is done all in one statement, does
the compiler optimize the assignment to b? If the assignment to b had,
say, twenty such concatenations in it, would there be a reason to use
StringBuilder?
Thanks very much.
Justin