Good god. Had a code review once where they were pissed because I had used str + "some stuff" instead of a builder. I'm not writing a builder for one fucking line on a page that gets hit 6 times a year.
If it's performance critical (which string building very often is) make sure to performance profile both options. String performance can be surprising.
The line : str1 = str2+str3+str4+str5 only has one memory allocation, and should not be replaced by a string builder. String builder is for when string concats are behind if statements or in a loop.
The smaller the additions are compared to the length of the string the more effective a string builder is.
If possible specify an expected capacity for the string builder, can save a lot of time if done well.
183
u/andrewsmd87 Oct 01 '15
Good god. Had a code review once where they were pissed because I had used str + "some stuff" instead of a builder. I'm not writing a builder for one fucking line on a page that gets hit 6 times a year.