The concatenation in many language using the += operator create a new string instance. It is preffered to use a string[] that we join at the end.
In Javascript :
var myString = new Array("Hello");
myString.push(" ");
myString.push("world !");
console.log(myString.join(''));
is more efficient that :
var myString = "Hello";
myString += " ";
myString += "world !";
console.log(myString);
In C#, does the += operator create a new string ?
Is the StringBuilder more efficient that using a string[] ?
a += bora = a + bgets translated toa = string.Concat(a, b)by the C# compilerStringBuilderis used to directly concatenate an arbitrary number of strings, whether in a collection or not -string.Joinis used to concatenate strings (from a collection) with a separator. If you want to useJointo concatenate strings with an empty separator there's nothing stopping you, but it's not the intended purpose.