I have a code like
enum WeekDays
{
Sat = 64,
Sun = 1,
Mon = 2,
Tue = 4,
Wed = 8,
Thu = 16,
Fri = 32
WorkDays = Sat | Sun | Mon | Tue | Wed
}
I would like to know more about:
WorkDays = Sat | Sun | Mon | Tue | Wed
What does its value mean?
You probably have a [Flags] attribute above that.
Workdays is created as the binary-or of the working day values (not my working days).
So the days are manually numbered to make them powers of 2 :
Sun = 0000001
Mon = 0000010
Tue = 0000100
Wed = 0001000
Sat = 1000000
etc
And then you can use binary operators to do Set operations:
MyWeekend = Sat | Sun; // 1000000 | 0000001 = 1000001
and use the binary-and to test membership:
WeekDays d = ...;
if ((d & MyWeekend) != 0)
{
// it's weekend !
}
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