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:
IsLeapYear(int year)

using System;

namespace forgetCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the year");

            int year = Convert.ToInt32(Console.ReadLine());
            
            if (DateTime.IsLeapYear(year))
            {
            Console.WriteLine("Leap Year");   
            }
            
            else
                Console.WriteLine("Not a Leap Year");                          
        }

    }
}


Output:
Enter the year
2004
Leap Year

Enter the year
2005
Not a Leap Year

..