[Flags]
enum Flaggy { None = 0, A=1, B=2, C=4, D=8}
Flaggy test;
or
bool A, B, C, D;
Is the flagged enum more efficient than the booleans or does it not really matter? In terms of cpu?
EDIT:
Yes I know that [Flags] doesn’t really do anything compared to a non-flags enums aside from adding a .ToString() method and some readability. Well, this piece of code is checked like 25000+ times per second so even a micro gain would be worth it. But a Flags Enum is nicer to read in the code compared to like 20 booleans and with .NET 4.0 the HasValue() makes up for the previously annoying checking for the Flags-values. But a method call in stead of an if-check is another micro cpu drain.
But reading the answers that came so quickly I guess it’s more a choice of readability than performance.
The flagged enum will be backed as a single Int32 in memory whereas the booleans will be stored as separate Boolean variables. So both will occupy the same memory.
In terms of CPU, with the enum you will need to perform bitwise operations to determine the values whereas with the booleans it’s a simple
ifso I guess it will be slightly faster. But that’s a premature optimization that you shouldn’t be concerned at all with. Both will be fast enough so pick the one that makes your code more readable.