If I have an enumeration with several values that may be present at the same time, I create an enumeration of flags:
[Flags] public enum Foo { None = 0, A = 1, B = 2, C = 4, D = 8 }
If I now want to convey the fact that each value is set, I would need to do something like this:
Bar bar = new Bar(Foo.A | Foo.B | Foo.C | Foo.D);
Would it be bad practice / malicious / blasphemy to add an extra All element?
All = 15
This will save some space and time when there are many values, and their transfer is a common scenario.
As far as I understand the mechanics of the flags enums (= bitfields), this should work. Are there any side effects that I don't have, or for other reasons, why you shouldn't do this?
source share