C#: Is year a leap year

Created by
Wednesday, August 3, 2016

Simple but quite common code used in a lot of situations where applications need to determine the date. This simple math based program allows us to easily determine if the year we have entered is a leap year or not.

 

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("www.dotnetdevelopernetwork.com");
 
        Console.WriteLine("Enter a year: ");
 
        int year;
        string result;
 
        Int32.TryParse(Console.ReadLine(), out year);
        result = year % 4 == 0 ? "Entry Is A Leap Year" : "Entry is Not A Leap Year.";
 
        Console.WriteLine(result);
        Console.ReadKey();
    }
}
0
Rating
1 2 3 4 5

Save

Saved

Report

Reported
Reasons
Cancel
0 comments