I have an enum in my application to represent the saving options where the user can save the image with lines drawn, circles, rectangles or any combination, so I declared an enum to represent the saving option.
enum SaveOption{lines,circles,rectangles};
How can I use operators to;
- Add option to the options
- Remove option from the options
Mark the enum with the
[Flags]attribute, and give each possible value a unique bit value:Then you can do this sort of thing:
Finally for ref, each option must have a value that is represented by a single bit, so in hex that’s
0x1,0x2,0x4,0x8, then0x10,0x20,0x40,0x80etc. Which is easier to remember than 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536. Which is as far as I remember 🙂