c# - How to use FlagsAttribute -


a developer on project has implemented following enum

[flags] public enum permissions {     overview = 1,     detail = 3,     edit = 7,     delete = 31,     block = 39, // requires edit = 7, , it's own location = 32. therefore 7 + 32 = 39.     unblock =  71, // requires edit = 7, , it's own location = 64. therefore 7 + 64 = 71.     = int.maxvalue } 

now, can see has, example, made details = 3. reason has done details (which should have been 2) includes overview (2+1=3).

i thought way these things use powers of 2 in enum , oring , anding outside of enum. what's going on here?

there's nothing wrong defining combinations in enum in order make life easier users of enum. said, short-sighted decision (inflexible , hard understand code) decision leave out various power-of-2 options make combinations.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -