I am using Enum flags in my application. The Enum can have around 50+ values, so values go up to 2^50. I was just wondering, can I use Math.Pow(2, variable)
to calculate these?
When I try to do that I get a constant value compile-time error. Is there another way, other than calculating these powers of 2 manually and putting it in?
Here's what I am doing:
[Flags]
internal enum RiskStates : long
{
None = 0,
AL = Convert.ToInt64(Math.Pow(2,0)),
AK = 2,
AZ = 4,
AR = 8,
CA = 16,
CO = 32,
CT = 64,
DC = 128,
DE = 256,
FL = 512,
GA = 1024,
HI = 2048,
ID = 4096,
IL = 8192,
IN = 16384,
IA = 32768,
KS = 65536,
KY = 131072,
LA = 262144,
ME = 524288,
MD = 1048576,
MA = 2097152,
MI = 4194304
}
AZ + AK
will be 6. Using powers of 2 avoid unwanted collision of combinations – Coachwhipn
the 50 and try and find some unique property such that alln
have that property and the other50-n
all don't. Well, amusing or not, depending on the party guests... – PsychometryList<State>
instead of a flags enum. The key observation is that very few people are likely to have lived in ten or more states. The List handles the small sets and singletons well, whereas the enum handles the huge number of extremely unlikely larger sets equally well, at the expense of, for example, not finding the count of states very easily. – Elmiraelmo