Searching on groups of enumerator's members

  • Thread starter Thread starter Craig Kenisston
  • Start date Start date
C

Craig Kenisston

Hi,

If have an enumerator like :

public enum {
op1,
op2,
op3,
op4,
op5}
// real list will contain about 30 members.

And I want to, let's say, group them in odd and evens, just to say an
example.
Then, I would be want to be able to say :

if (myOp.OpX is in the list of odd operators)

or do :

if (myOp.OpX is in the list of even operators)


What 's the C# approach to do this ?

I would this in Delphi very easy, but I don't find the C#'s correspoding
approach.


Regards,
 
return ((myOp.OpX % 2 == 0) ? "Even" : "Odd");

C# isnt my language so this might be wrong,

return iif(myOp.Opx Mod 2 = 0, "Even", Odd")
 
Jared :

Thanks for your input.
Actually I said "even and odds, just to say an example".

But I've just found how to group them :

public enum {
op1,
op2,
op3,
op4,
op5,
EvenOps = op2 | op4,
OddsOps = op1 | op3 | op5,
}


Regards,
 
Craig,
So is the concept, the snippet just followed your example, you can still use
that block with your or'd variable.
Jared
 
Back
Top