Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

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?
0
bobdylan75
Asked:
bobdylan75
  • 2
1 Solution
 
p_davisCommented:
you can just cast it

Anum = (int)A;

or convert

Anum = Convert.ToInt32(A);
0
 
bobdylan75Author Commented:
thanks ;)
0
 
dexterrajeshCommented:
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

0
 
bobdylan75Author Commented:
thanks Dexter anyway
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now