String output: format or concat in C#?

I’m amazed that so many people immediately want to find the code that executes the fastest. If ONE MILLION iterations STILL take less than a second to process, is this going to be in ANY WAY noticeable to the end user? Not very likely.

Premature optimization = FAIL.

I’d go with the String.Format option, only because it makes the most sense from an architectural standpoint. I don’t care about the performance until it becomes an issue (and if it did, I’d ask myself: Do I need to concatenate a million names at once? Surely they won’t all fit on the screen…)

Consider if your customer later wants to change it so that they can configure whether to display "Firstname Lastname" or "Lastname, Firstname." With the Format option, this is easy – just swap out the format string. With the concat, you’ll need extra code. Sure that doesn’t sound like a big deal in this particular example but extrapolate.

Leave a Comment