|
-
Jun 22nd, 2003, 09:48 PM
#1
Thread Starter
yay gay
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?
\m/  \m/
-
Jun 23rd, 2003, 10:49 AM
#2
Lively Member
And (&) and Or (|) work with enums
-
Jun 23rd, 2003, 10:52 AM
#3
Thread Starter
yay gay
yes but then how to read? how to know if my enum has .Value1, or .Value2, or .Value1 and .Value2?
\m/  \m/
-
Jun 23rd, 2003, 11:04 AM
#4
Lively Member
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
-
Jun 23rd, 2003, 11:10 AM
#5
Lively Member
You can do this also:
test mybyte = test.h2 & test.h3;
if (mybyte == test.h1)
Console.WriteLine("success");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|