Why isn’t Byte the default backing type for enumerations?
Int32 seems like overkill. Every Enum I have ever used has contained under 20 values. It’s a micro-optimization, but it seems as though all common usages have under 256 values [in my limited experience].
Is there a more technical reason, or is just to make sure “all common” scenarios of Enum usage work fine and Int32 isn’t really that expensive in all but the corner cases?
In addition I have gotten the implication the compiler does not change the backing type (or no one has mentioned that it optimizes enumerations in what I’ve read). Does it optimize the backing type since it knows the range of values at compile time?
Because the x86 instruction set supports int32 operations natively. There is no performance gain when using int8 operands. Also are memory accesses to operands that are naturally aligned (32bit on a address divisible by 32) carried out faster than if a sub-word has to be shuffled first.