Introducing Radical.sh

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

Printing only month numbers in a year in C#

  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("MM"));
  13. now = now.AddMonths(1);
  14. }
  15. }
  16.  
  17. }
  18. }


Output:
07
08
09
10
11
12
01
02
03
04
05
06

...