Create month names programatically

Please help me to create month names (January, February…December) programatically. I do not want to hardcode the month names.

Thank you in advance.

  1. Create a new array of strings with a size 12.

String[] arrMonths = new String[11]

  1. Create one DateTime variable.

DateTime dt

  1. Create an integer variable “index” with a default value zero and use foreach loop to set month names.

     ForEach index in Enumerable.Range(0,11)
       dt = new DateTime(DateTime.Now, index,1)
       arrMonths(index) = dt.ToString("MMMM")

Now the array contains all month names.

Karthik Byggari


1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.