Link to home
Start Free TrialLog in
Avatar of bobdylan75
bobdylan75Flag for Afghanistan

asked on

How to obtain the int value of an enum variable (c# vs2005)

Hi,
I have define an enum type.
So, I'd like to use the integer value associated
to the particulaer enum value.
if I have an enum typeX:
One, 1
Two, 2
Tree, 3

I'd like auto-retrieve the value 2 when I have a variable A = typeX.Two
something like Anum= enumCounter( A )
so that Anum equals to 2

Is it possible?
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobdylan75

ASKER

thanks ;)
hi,

using System;
public class EnumTest 
{
   enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};

   public static void Main() 
   {
      int x = (int) Days.Sun;
      int y = (int) Days.Fri;
      Console.WriteLine("Sun = {0}", x);
      Console.WriteLine("Fri = {0}", y);
   }
}

Open in new window

thanks Dexter anyway