Is there an easier way of writing base 2 numbers in Flags?
Is there an easier way to write the integer value for enum flags witho开发者_运维技巧ut having to remember EACH base 2 number (I tend to get lost after 4096)?
If I use, let's say, 2*2*2*2
, will that be converted to 16 at compile time or will it be executed at run time?
public enum Foo
{
Bar = 1 << 0,
Baz = 1 << 1,
Quux = 1 << 2,
Etc = 1 << 3
}
You could use hex which is a little more intuitive.
Value1 = 0x01,
Value2 = 0x02,
Value3 = 0x04,
...
Or use bit shifts.
Value1 = 1 << 0,
Value2 = 1 << 1,
Value3 = 1 << 2,
....
精彩评论