Results 1 to 5 of 5

Thread: Enum question

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    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/

  2. #2
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    And (&) and Or (|) work with enums

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yes but then how to read? how to know if my enum has .Value1, or .Value2, or .Value1 and .Value2?
    \m/\m/

  4. #4
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    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

  5. #5
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    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
  •  



Click Here to Expand Forum to Full Width