C# Extension Method shortcut for Format

Posted by Blake on 1/23/2012
)

Some people hate extension methods used like this, but in my own projects where I’m going to be the only coder, I find it saves me time. I found this one useful. Also, I needed a first post since moving my blog from Wordpress.com to a self installation on my own site. :D

using System;
using System.Linq

public static class StringExtensions
{
    public static string Format(this string format, object arg, params object[] additionalArgs)
    {
        if (additionalArgs == null || additionalArgs.Length == 0)
        {
            return string.Format(format, arg);
        }
        else
        {
            return string.Format(format, new object[] { arg }.Concat(additionalArgs).ToArray());
        }
    }
}