I was surprised to see an example of a string being initialised to null and then having something appended to it in a production environment. It just smelt wrong.
I was
The relevant citation should be ECMA-334 §14.7.4:
String concatenation:
string operator +(string x, string y); string operator +(string x, object y); string operator +(object x, string y);
The binary
+
operator performs string concatenation when one or both operands are of typestring
. If an operand of string concatenation isnull
, an empty string is substituted. Otherwise, any non-string operand is converted to its string representation by invoking the virtualToString
method inherited from typeobject
. IfToString
returnsnull
, an empty string is substituted.