How to find a leap year using C# ?

By | April 18, 2011

Hi,

Sometimes you may need to find whether a particular year is leap year or not. But how can you find out whether a particular year is leap year or not in C# ? Use the following code.

using System;

class MainClass
{
  public static void Main()
  {

    bool myResult= DateTime.IsLeapYear(2011);
    Console.WriteLine("Is the year 2011 a leap year ? = " + myResult);
  }

}

And the output is,
Is the year 2011 a leap year ? = False

🙂

2 thoughts on “How to find a leap year using C# ?

  1. Dharmendra

    In sql

    declare @num int;
    set @num=1996;
    select case when (@num%4)=0 and ((@num%100)0 and (@num%400)0) then ‘Yes’ else ‘no’ end;

    Reply

Leave a Reply

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