我正在使用 C# 并试图找出给定的日期和月份是否对闰年有效。这是我的代码:
static void Main(string[] args)
{
Console.WriteLine("The following program is to find whether the Date and Month is Valid for an LEAP YEAR");
Console.WriteLine("Enter the Date");
int date = Convert.ToInt16(Console.ReadLine()); //User values for date and month
Console.WriteLine("Enter the Month");
int month = Convert.ToInt16(Console.ReadLine());
{
if (month == 2 && date < 30) //Determination of month and date of leap year using If-Else
Console.WriteLine("Your input is valid");
else if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && date < 32)
Console.WriteLine("Your inpput valid1");
else if (( month == 4 || month == 6 || month == 9 || month == 11 ) && date < 31)
Console.WriteLine("Your inpput valid2");
else
Console.WriteLine("Your input INvalid");
Console.ReadKey();
}
}
我的问题是,我可以使用DateTime
这个程序还是更好的方法?欢迎任何建议。