Reputation: 968
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;
}
}
Upvotes: 0
Views: 89
Reputation: 941525
You reversed the arguments for the DaysInMonth method. Year goes first.
Upvotes: 2
Reputation:
You have your DateTime.DaysInMonth()
call backwards. Change it to this:
DateTime.DaysInMonth(year, month)
When you put the year
variable in the place of month
, it was greater than the max that it can be (greater than 12), resulting in the ArgumentOutOfRangeException
.
Upvotes: 8