首页 > 技术文章 > try判断是不是闰年try-catch

dlexia 2015-04-03 08:46 原文

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string rn = Console.ReadLine();
                string s = "";
                try
                {
                    DateTime rn1 = Convert.ToDateTime(rn + "-2-29");系统自动判断,根据系统时间
                    s = "年是闰年";
                }
                catch (Exception)
                {
                    s = "年不是闰年";
                }
                finally
                {
                    Console.WriteLine(rn+s);
                }
            }
        }
    }
}

 

推荐阅读