A while back a post by Jon Skeet planted the idea in my head of building a CompiledFormatter
class, for using in a loop instead of String.Format()
.
The framework provides explicit overrides to the format methods that take fixed-sized parameter lists instead of the params object[] approach to remove the overhead of allocating and collecting all of the temporary object arrays. You might want to consider that for your code as well. Also, providing strongly-typed overloads for common value types would reduce boxing overhead.