If performance is important, try to completely abandon AppendFormat (). Instead, use multiple calls to Append () or AppendLine (). This makes your code larger and less readable, but it is faster because you do not need to parse strings. Parsing strings is slower than you could imagine.
I usually use:
sbuilder.AppendFormat("{0} line", "First"); sbuilder.AppendLine(); sbuilder.AppendFormat("{0} line", "Second"); sbuilder.AppendLine();
If performance is not critical, then I would use:
sbuilder.Append("First"); sbuilder.AppendLine(" line"); sbuilder.Append("Second"); sbuilder.AppendLine(" line");
(Of course, this makes sense if "First" and "Second", where there are no string literals)
Chris Dec 08 '08 at 17:46 2008-12-08 17:46
source share