The error I’m getting is “System.ArgumentOutOfRangeException was unhandled.” It asks that month be between 1 and 12. But look at the variable in the debugger says it equals to 1, along with a 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;
}
}
You have your
DateTime.DaysInMonth()call backwards. Change it to this:When you put the
yearvariable in the place ofmonth, it was greater than the max that it can be (greater than 12), resulting in theArgumentOutOfRangeException.DateTime.DaysInMonth()