While learning the flag technique, I ran into some problem, so I am showing this example using C # with Enum:
[Flags] enum PermissionTypes : byte { None = 0x0, Read = 0x1, Write = 0x2, Modify = 0x4, Delete = 0x8, Create = 0x10, All = Read | Write | Modify | Delete | Create }
To check the hasFlag property:
if((value & mask) == mask) {...}
But when "hasFlag" applies to both "None" and "Read":
Denote x = Current_Permission_Setting, x & PermissionTypes.None = always false x & PermissionTypes.Read = always true IFF
(cont ') IFF x = { ODD byte value}
Question: What are the ideal sets of flag values ββthat can be safely used?
Help: Here is a complete example .
source share