gpt4 book ai didi

c# - C#中假设的可能性

转载 作者:行者123 更新时间:2023-11-30 19:39:09 24 4
gpt4 key购买 nike

我可以对 C# 中系统枚举的转换 int 值做出假设吗?

例如:

//DayOfWeek
(int)DayOfWeek.Monday == 1,
(int)DayOfWeek.Tuesday == 2,
(int)DayOfWeek.Wednesday == 3,
(int)DayOfWeek.Thursday == 4,
(int)DayOfWeek.Friday == 5,
(int)DayOfWeek.Saturday == 6,
(int)DayOfWeek.Sunday == 0

我的代码的逻辑取决于它。但是,我不想编写自己的映射,因为它...只是一个错误的解决方案。

编辑文化也来了。 ISO 标准 - 星期一,第一天。在美国 - 第一天星期日。

最佳答案

是的,你可以依靠它,只要它是documented那:

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

当然,虽然他们不太可能这样做,但 Microsoft 可以在未来的版本中自由更改此设置。

关于c# - C#中假设的可能性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29173611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com