Can Calendar.GetDayOfWeek () return (DayOfWeek) 7?

I look through the code and found this bit (rewritten):

if ((int)CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(someDate) == 7) ...

I would think that this condition always returns false, because DayOfWeek (return type) is in the range from 0 to 6, or can it return 7 in a certain culture?

+3
source share
3 answers

Normally GetDayOfWeek will never return the (converted) value of 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.

+1
source

DayOfWeek , . DayOfWeek.Sunday DayOfWeek.Saturday. , ( DayOfWeek.Sunday) ( DayOfWeek.Saturday).

- http://msdn.microsoft.com/en-us/library/system.dayofweek.aspx

+3

DayOfWeek MSDN?

DayOfWeek , . DayOfWeek.Sunday DayOfWeek.Saturday. , ( DayOfWeek.Sunday) ( DayOfWeek.Saturday).

+2

Source: https://habr.com/ru/post/1789757/


All Articles