Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Printing months in a year in C#

We can print the months of a year like below using MMMM format.

  1. using System;
  2.  
  3. namespace forgetCode
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. DateTime now = DateTime.Today;
  10. for (int i = 0; i < 12; i++)
  11. {
  12. Console.WriteLine(now.ToString("MMMM"));
  13. now = now.AddMonths(1);
  14. }
  15. }
  16.  
  17. }
  18. }


Output:
July
August
September
October
November
December
January
February
March
April
May
June

..