Introducing Radical.sh

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

Printing year by adding months and days in C#

C# will automatically look into months and days added to the input date and act correspondingly.

  1. using System;
  2.  
  3. namespace forgetCode
  4. {
  5. namespace forgetCode
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. DateTime now = DateTime.Today;
  12.  
  13. Console.WriteLine(now.ToString("yyyy"));
  14.  
  15. DateTime then = now.AddMonths(12);
  16.  
  17. Console.WriteLine(then.ToString("yyyy"));
  18.  
  19. DateTime thenafter = then.AddDays(365);
  20.  
  21. Console.WriteLine(thenafter.ToString("yyyy"));
  22. }
  23.  
  24. }
  25. }
  26. }


Output:
2012
2013
2014

..