The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
.NET Framework 4.5
Returns an indication whether the specified year is a leap year.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- year
- Type: System.Int32
A 4-digit year.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | year is less than 1 or greater than 9999. |
The following example uses the IsLeapYear method to determine which years between 1994 and 2014 are leap years. The example also illustrates the result when the AddYears method is used to add a year to a leap day.
using System; public class IsLeapYear { public static void Main() { for (int year = 1994; year <= 2014; year++) { if (DateTime.IsLeapYear(year)) { Console.WriteLine("{0} is a leap year.", year); DateTime leapDay = new DateTime(year, 2, 29); DateTime nextYear = leapDay.AddYears(1); Console.WriteLine(" One year from {0} is {1}.", leapDay.ToString("d"), nextYear.ToString("d")); } } } } // The example produces the following output: // 1996 is a leap year. // One year from 2/29/1996 is 2/28/1997. // 2000 is a leap year. // One year from 2/29/2000 is 2/28/2001. // 2004 is a leap year. // One year from 2/29/2004 is 2/28/2005. // 2008 is a leap year. // One year from 2/29/2008 is 2/28/2009. // 2012 is a leap year. // One year from 2/29/2012 is 2/28/2013.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.