Check Leap Year in C#

Hi there, as I said in previous post this will be a simple c# code on how to check if a year is leap year, as I said this is a very basic algorithm but I wanted to have it documented.

class Program
    {
        static void Main(string[] args)
        {
            int input = 2020;
 
            bool result = IsLeapYear(input);
 
            Console.WriteLine("Input: {0}, Is leap year?: {1}", input, result);
            Console.ReadLine();
        }

        /// <summary>
        /// Calculate if a input year is a Leap year.
        /// </summary>
        /// <param name="input">Input year</param>
        /// <returns>Where if it is leap year or not, true/false</returns>

        private static bool IsLeapYear(int input)
        {
            // leap year mod 4 is always equals 0 (multiple of 4)
            if (input % 4 == 0)
                return true;
            else
                return false;
        }
    }

 

Leave a Reply

Your email address will not be published. Required fields are marked *