Thread: Enum comparison not working.

  1. #1
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271

    Enum comparison not working.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            public enum TagLabels : uint
            {
                TurnLeft = 0x0000000000000000000030A38DB1,
                TurnRight = 0x00000000000000000000307346CC,
                LiftApproach = 0x0000000000000000000012107A8D
            }
            
            static void Main(string[] args)
            {
                TagLabels friend;
                string Tag = TagLabels.TurnRight.ToString();
                string actual, returned;
                actual = "0x0000000000000000000012107A8D";
                returned = "0x0000000000000000000012107A8D";
                
                if (actual == TagLabels.LiftApproach.ToString() )
                    Console.WriteLine("equivalent");
    
                friend = (TagLabels)Enum.Parse(typeof(TagLabels), actual);
                Console.Write("Attempting to convert: ");
                Console.WriteLine(actual);
                
                Console.Read();
            }
        }
    }
    Can some one tell me what's wrong with the section in bold please?
    I have no idea why it wont work.
    Last edited by WDT; 08-13-2009 at 10:12 AM. Reason: Incorrect code version.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Because
    Code:
    TagLabels.LiftApproach.ToString()
    is LiftApproach. Check your debugger. Also your method of comparison is pretty wierd, why cant you just compare one enum to another, or an enum to the number value. Also why are you preceeding so many meaningless zeros?

  3. #3
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Because that's the return of a possible list of devices from a reader... Also I solved it. I needed to compare a return to the enum list so that I can use it to set another variable in the class.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by WDT View Post
    Because that's the return of a possible list of devices from a reader... Also I solved it. I needed to compare a return to the enum list so that I can use it to set another variable in the class.
    His point with the zeros comment was that the compiler ignores them completely. These are equivalent:

    Code:
                TurnLeft = 0x0000000000000000000030A38DB1,
                TurnRight = 0x00000000000000000000307346CC,
                LiftApproach = 0x0000000000000000000012107A8D

    Code:
                TurnLeft = 0x30A38DB1,
                TurnRight = 0x307346CC,
                LiftApproach = 0x12107A8D
    There's no difference between the two at all. They both are the exact same value to the compiler.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  3. my comparison isn't working
    By Rubiks14 in forum C++ Programming
    Replies: 3
    Last Post: 10-02-2005, 07:50 PM
  4. enum question
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 08-10-2002, 12:33 PM
  5. friends class lil prblm with enum
    By rip1968 in forum C++ Programming
    Replies: 4
    Last Post: 07-25-2002, 09:57 PM