Calendar.GetDayOfWeek() 可以返回 (DayOfWeek)7 吗?

发布于 2024-10-15 20:49:26 字数 206 浏览 3 评论 0原文

我正在审查一些代码并发现这一点(重写):

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷→糖丶微凉 2024-10-22 20:49:26

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

时间你老了 2024-10-22 20:49:26

您是否查看过 MSDN 上的 DayOfWeek 枚举页面

DayOfWeek 枚举表示每周有 7 天的日历中的星期几。此枚举中常量的值范围从 DayOfWeek.Sunday 到 DayOfWeek.Saturday。如果转换为整数,则其值范围从零(表示 DayOfWeek.Sunday)到 6(表示 DayOfWeek.Saturday)。

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).

飘落散花 2024-10-22 20:49:26

通常 GetDayOfWeek 永远不会返回(转换后的)值 7。

从代码中很难看出程序员想要什么。我建议将其重写为:

if (CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(someDate) == DayOfWeek.Saturday) ...

或者其他什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文