它是安全的假设星期几的数值? [英] Is it safe to assume DayOfWeek's numeric value?

查看:122
本文介绍了它是安全的假设星期几的数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一周的日存储在数据库中,其中1表示星期日,星期一= 2等

I have the day of the week stored in a database, where Sunday = 1, Monday = 2 etc.

在从数据库的查询时,我需要当日转换为 System.DayOfWeek

In a query from the database, I need to convert the day to System.DayOfWeek.

据的 MSDN

常量的值此枚举范围从 DayOfWeek.Sunday DayOfWeek.Saturday 。如果强制转换为整数,取值范围从零(表示 DayOfWeek.Sunday )六(表示 DayOfWeek.Saturday )。

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

这意味着,我查询数据后,我需要减去1之前,我转换结果星期几

This means that after I query the data, I need to subtract 1 before I convert the result to DayOfWeek.

这安全吗?结果
或做我需要担心星期几改变?

推荐答案

是的,这是安全,你不应该担心的值发生变化。这里的枚举是如何定义的:

Yes, this safe, you should not worry about the values changing. Here's how the enum is defined:

public enum DayOfWeek
{
    Friday = 5,
    Monday = 1,
    Saturday = 6,
    Sunday = 0,
    Thursday = 4,
    Tuesday = 2,
    Wednesday = 3
}

如果这些值在BCL改变,一个地狱很多的代码将打破。

If those values change in the BCL, a hell lot of a code will break.

这篇关于它是安全的假设星期几的数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆