Introducing Radical.sh

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

Checking for Leap year in C#

We can check easily whether a year is a leap year or not by using IsLeapYear() function.

Syntax:
  1. IsLeapYear(int year)

  1. using System;
  2.  
  3. namespace forgetCode
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.WriteLine("Enter the year");
  10.  
  11. int year = Convert.ToInt32(Console.ReadLine());
  12. if (DateTime.IsLeapYear(year))
  13. {
  14. Console.WriteLine("Leap Year");
  15. }
  16. else
  17. Console.WriteLine("Not a Leap Year");
  18. }
  19.  
  20. }
  21. }


Output:
Enter the year
2004
Leap Year

Enter the year
2005
Not a Leap Year

..