String.Format is your friend

One of the consultants that works for me was trying to figure out the best way to format strings for writing messages to the event log for a Windows service he’s writing.  He was using the horrifying “blah blah blah” + + “blah blah blah” pattern that I despise.  So I took about 60 seconds to explain the goodness of String.Format to him.  It didn’t take much longer than that to convert him to using it.

A quick Google search revealed an excellent String.Format 101 blog post by Kathy Kam. Karl Seguin’s post on the same topic brings performance advantages into the discussion.  Another bit of information I didn’t know before reading his post was that the StringBuilder class has an equivalent AppendFormat method.