C# enum gotcha!

If you define an enum with the Flags attribute, you expect that when you do an "&" operation with an enum value, you will get back the enum value you are "&" with, only if it contains within the value.

Wrong!

If you have a enum value with its numeric value set to "0", and you do:

value & zeroValue == zeroValue

You will always get zeroValue back, even if the actual enum value never had the zero value specified!!

Comments

Popular posts from this blog

Tutorial: Using Google Cloud Storage from C# and .NET

Late 2008 Macbook only giving 1.5 gb/s speed with 6 gb/s Intel SSD?

Enable Visual Studio to use more than 2GB of memory