I have the day of the week stored in a database, where Sunday = 1, Monday = 2 etc.
In a query from the database, I need to convert the day to System.DayOfWeek
.
According to MSDN:
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).
This means that after I query the data, I need to subtract 1 before I convert the result to DayOfWeek
.
Is this safe?
Or do I need to worry about the numeric values of DayOfWeek
changing?
Yes, this safe, you should not worry about the values changing. Here's how the enum is defined:
public enum DayOfWeek
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
}
If those values change in the BCL, a hell lot of a code will break.
Yes always safe,you can go back and front :
return DateTime.Today.AddDays(-1);
and
return DateTime.Today.AddDays(1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With