Enum flags over 2^32

When I try to do that I get a constant value compile-time error.

You’d actually be okay if you used the L suffix to force it to be a long literal – but it’s still not ideal to have to specify them all manually. (It’s not “obviously correct” when reading the code.)

You can’t use Math.Pow as the expression has to be a compile-time constant – but you can use bit-shifting:

None = 0,
AL = 1L << 0,
AK = 1L << 1,
AZ = 1L << 2

etc. I’d argue that’s more readable anyway 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)