c# - Parsing an enum with the Flags attrubute not giving expected value -


my enum:

        [flags]         public enum equalityoperator         {             equal,             notequal,             lessthan,             lessthanorequal,             greaterthan,             greaterthanorequal,             like,             notlike,             in,             notin         } 

my code parsing it:

var operatorval = (equalityoperator)enum.parse(typeof (equalityoperator), filterinfo[3]); 

when debug, can see filterinfo[3] "like"

however, operatorval comes out "lessthan | greaterthan"

what missing? can not parse enums flags attribute?

you need specify values:

[flags] public enum equalityoperator {     equal = 0,     notequal = 1,     lessthan = 2,     lessthanorequal = 4,     greaterthan = 8,     greaterthanorequal = 16,     = 32,     notlike = 64,     in = 128,     notin = 256  } 

the reason like parsing lessthan | greaterthan because you've defined it, lessthan has value 2 , greaterthan has value 4. if take bitwise-or of these, end lessthan | greaterthan = 6. look, like has value 6 you've defined enum! so, did parse "correctly".

i'll frank though, don't see point of marking enum flags though. point of flags can bitwise operations on enum values. why think need bitwise operations on values of enum?


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -