我得到的錯誤是「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