This has always bugged me. Perhaps someone with some hardcore knowledge of .NET internals can explain it to me.
Suppose I define an enum as follows:
publ
Range-checking has a potentially unnecessary cost. It's therefore reasonable to not perform it implicitly. As already mentioned, [Flags]
require that no such checking takes place. If the runtime would check for the presence of [Flags]
, this would still incur a runtime penalty every time you perform a conversion.
The only way around this would be for the compiler to be aware of the [Flags]
attribute. I guess this wasn't done to reduce the amount of runtime knowledge hardcoded into the compiler.