SYSK 196: Is there a performance hit and CPU spike when concatenating literal strings?
For example, is doing something like the code snippet below (done for readability) falls into the "bad practices" category?
string x = "<root>" +
" <items>" +
" <item>" +
" <name>xyz</name>"
" </item>" +
" </items>" +
"</root>";
The answer is – no! The complier is smart enough to create one large string.
Of course, executing
string x = "xyz " + myVar + " 123";
is a totally different story... Do use string.Format or StringBuilder instead in such cases, e.g.
string x = string.Format("xyz %1 123", myVar);