C#闰年检查

Fre*_*tor 0 c#

我正在尝试制作一个显示一个月内天数的程序,我需要增加闰年,所以我要求年份和我试图找出闰年的方式是检查如果年份是4的倍数,它表示它"不能采用给定表达式的地址".这是我的代码:

 if (month == 2)
      Console.WriteLine("\nThere are 28 days in Febuary");

 if (month == 2) &(4%year);
      Console.WriteLine("\nThere are 29 days in Febuary this year as it is a leap year");
Run Code Online (Sandbox Code Playgroud)

小智 5

使用:

DateTime.IsLeapYear(year)
Run Code Online (Sandbox Code Playgroud)