You can fix it by not writing anything similar, ever. Nested "if", hard-coded
immediate constants — not only this is totally non-maintainable, but is pain to see.
All the month names are already in the system. Each of the months is not the separate case, it's just one short fragment of code, not depending on month value. Here is the simple idea: create an instance of
System.DateTime
and set a month property to required value, them format it using
System.DateTime.ToString(string format)
. Please see:
DateTime Constructor (Int32, Int32, Int32) (System)[
^] (year and day don't matter, use any, with specified month),
DateTime.ToString Method (String) (System)[
^].
For format, use "full name of the month" format, which is "MMMM". Custom formats are explained here:
Custom Date and Time Format Strings[
^].
This way, you won't need any "if" or "switch-case" statements, or perhaps just one, checking up if the value is withing the range 1 to 12.
That's all. Please, before asking me about further detail, try to do it all by yourself; it's way too simple.
—SA