首页 > 代码库 > C#判断闰年函数及举例

C#判断闰年函数及举例

//语法:
public static bool IsLeapYear(int year)
//用法举例:
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"));
         }         
      }
   }
}

C#判断闰年函数及举例