An extension approach to get the name of a month

by Mikael Henriksson 17. February 2009 21:15

I am as I have posted before lazy. I am also very hesitant to using extension methods. There is nothing wrong with this but they pop up everywhere eventually. I did however create an extremely useful extension method for something as simple as getting the name of a specified dates month. This is displayed based on the current culture.

It is only one line of code but it’s one hell of a line to remember and that’s why I created the extension for it! :)

using System.Threading;
public static string MonthName(this DateTime date)
{
	return Thread
	.CurrentThread
	.CurrentCulture
	.DateTimeFormat
	.MonthNames[date.Month];
}

Tags:

C#

blog comments powered by Disqus