Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a predefined enumeration for Month in the .NET library?

I'm looking to see if there is an official enumeration for months in the .net framework.

It seems possible to me that there is one, because of how common the use of month is, and because there are other such enumerations in the .net framework.

For instance, there is an enumeration for the days in the week, System.DayOfWeek, which includes Monday, Tuesday, etc..

I'm wondering if there is one for the months in the year, i.e. January, February, etc?

Does anyone know?

like image 423
Mark Rogers Avatar asked May 22 '09 19:05

Mark Rogers


People also ask

Are enumeration available in C#?

An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword. C# enumerations are value data type. In other words, enumeration contains its own values and cannot inherit or cannot pass inheritance.

What is .NET enumeration?

An enumeration type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type. To define an enumeration type, use the enum keyword and specify the names of enum members: C# Copy. enum Season { Spring, Summer, Autumn, Winter }


Video Answer


2 Answers

There isn't, but if you want the name of a month you can use:

CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName (DateTime.Now.Month); 

which will return a string representation (of the current month, in this case). Note that GetMonth takes arguments from 1 to 13 - January is 1, 13 is a blank string.

like image 68
Andy Mikula Avatar answered Sep 20 '22 15:09

Andy Mikula


No, there isn't.

like image 32
David Nelson Avatar answered Sep 16 '22 15:09

David Nelson