我得到的错误是“System.ArgumentOutOfRangeException was unhandled。”它要求月份在1和12之间。但是看看调试器中的变量,它等于1以及一个Debug.Writeline。循环中的歧义?
int month, year, total;
total = 0;
DateTime dayToFind;
for (year = 1001; year < 1201; year++){
for (month = 1; month < 12; month++){
dayToFind = new DateTime(year, month, DateTime.DaysInMonth(month, year));
// The error points at the last occurance of month above.
total = (dayToFind.DayOfWeek == DayOfWeek.Monday) ? 1 : 0;
}
}
不应该是'month = 1;月<13岁,或者你故意跳过12月? –
是的,当我切换机器时,我输入的太快而不是仅仅复制和粘贴。另请注意'total ='应该是'total + ='。除非我喜欢循环而不是实际聚合。 – surfasb