C# String.format extension method
Posted
by
Paul Roe
on Programmers
See other posts from Programmers
or by Paul Roe
Published on 2011-06-22T21:10:48Z
Indexed on
2011/06/23
0:31 UTC
Read the original article
Hit count: 355
With the addtion of Extension methods to C# we've seen a lot of them crop up in our group. One debate revolves around extension methods like this one:
public static class StringExt
{
/// <summary>
/// Shortcut for string.Format.
/// </summary>
/// <param name="str"></param>
/// <param name="args"></param>
/// <returns></returns>
public static string Format(this string str, params object[] args)
{
if (str == null) return null;
return string.Format(str, args);
}
}
Does this extension method break any programming best practices that you can name? Would you use it anyway, if not why? If I renamed the function to "F" but left the xml comments would that be epic fail or just a wonderful savings of keystrokes?
© Programmers or respective owner