-
Enum question
i've seen several times than enum types are addictive..i mean..i have an enumeration and i can have a single variable of that enum store various values.. in vb.net u do myEnum.Value1 + myEnum.Value2 if i am not mistaken..how do i do this in c#? i have the impression u do this thru the | operator..or not? and how to evaluate an enum to know which things have been selected or not?
-
And (&) and Or (|) work with enums
-
yes but then how to read? how to know if my enum has .Value1, or .Value2, or .Value1 and .Value2?
-
public enum test: byte
{h1, h2, h3, h4}
test mybyte = test.h2 | test.h3;
Console.WriteLine(mybyte);
// displays h4 which is 3 which is the result of Or'ing a binary 1 and 2
test mybyte = test.h2 & test.h3;
Console.WriteLine(mybyte);
// displays h1 which is 0 which is the result of And'ing a binary 1 and 2
-
You can do this also:
test mybyte = test.h2 & test.h3;
if (mybyte == test.h1)
Console.WriteLine("success");