Introducing Radical.sh

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

Days in a month in C#

You can get the total days in a month easily by giving year and month as inputs.
Year is mandatory here because C# has to validate like leap year functionality internally.
(i.e) 2011 - 02 --> 28 days
2012 -02 --> 29 days.

Syntax:
  1. DaysInMonth(int year, int month)


Example:

  1. using System;
  2.  
  3. namespace forgetCode
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.WriteLine("Enter year");
  10. int year = Convert.ToInt32(Console.ReadLine());
  11.  
  12.  
  13. Console.WriteLine("Enter month");
  14. int month = Convert.ToInt32(Console.ReadLine());
  15.  
  16. Console.WriteLine("Days in the month:"+DateTime.DaysInMonth(year,month));
  17. }
  18.  
  19. }
  20. }


Output:

Enter year
2012
Enter month
02
Days in the month :29


Enter year
2015
Enter month
02
Days in the month :28


..