Calendar.GetDayOfWeek() 可以返回 (DayOfWeek)7 吗?
我正在审查一些代码并发现这一点(重写):
if ((int)CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(someDate) == 7) ...
我认为这个条件总是返回 false,因为 DayOfWeek (返回类型)范围从 0 到 6,或者这最终会在特定文化中返回 7 吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DayOfWeek 枚举表示每周有 7 天的日历中的星期几。此枚举中常量的值范围从 DayOfWeek.Sunday 到 DayOfWeek.Saturday。如果转换为整数,则其值范围从零(表示 DayOfWeek.Sunday)到 6(表示 DayOfWeek.Saturday)。
来源 - http://msdn.microsoft.com/en-us/library /system.dayofweek.aspx
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
您是否查看过 MSDN 上的 DayOfWeek 枚举页面?
Did you take a look at the DayOfWeek enum page on MSDN?
通常 GetDayOfWeek 永远不会返回(转换后的)值 7。
从代码中很难看出程序员想要什么。我建议将其重写为:
或者其他什么。
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:
Or something.