Reputation: 3686
I'm reviewing some code and found this bit (rewritten):
if ((int)CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(someDate) == 7) ...
I would think this condition always returns false since DayOfWeek (the return type) ranges from 0 to 6, or could this eventually return 7 in a specific culture?
Upvotes: 3
Views: 2634
Reputation: 52518
Normally GetDayOfWeek will never return a (converted) value 7.
From the code it is very unclear what the programmer wants. I suggest rewriting it as:
if (CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(someDate) == DayOfWeek.Saturday) ...
Or something.
Upvotes: 1
Reputation: 55489
The DayOfWeek enumeration represents the day of the week in calendars that have seven days per week. The value of the constants in this enumeration ranges from DayOfWeek.Sunday to DayOfWeek.Saturday. If cast to an integer, its value ranges from zero (which indicates DayOfWeek.Sunday) to six (which indicates DayOfWeek.Saturday).
Source - http://msdn.microsoft.com/en-us/library/system.dayofweek.aspx
Upvotes: 3
Reputation: 18286
Did you take a look at the DayOfWeek enum page on MSDN?
The DayOfWeek enumeration represents the day of the week in calendars that have seven days per week. The value of the constants in this enumeration ranges from DayOfWeek.Sunday to DayOfWeek.Saturday. If cast to an integer, its value ranges from zero (which indicates DayOfWeek.Sunday) to six (which indicates DayOfWeek.Saturday).
Upvotes: 2