Jak*_*ake 2 c# arrays winforms leap-year c#-4.0
我需要计算程序运行时的当前年份是否为闰年(可被4整除,不能被100整除但可被400整除)但不使用DateTime.LeapYear属性.谁能提出任何建议?
// DateTimePicker代码
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime now;
int[] months = {31,28,31,30,31,30,31,31,30,31,30,31};
now = DateTime.Now.Date;
if (now.Year / 4 == 0 && now.Year / 400 == 0)
{
months(1) = 29;
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这包括三个标准:
var year = now.Year;
if (year % 4 == 00 && !(year % 100 == 0 && year % 400 != 0))
{
....
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1340 次 |
| 最近记录: |