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

Posted on 2011-10-19
Last Modified: 2013-12-16
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?
Question by:bobdylan75
    LVL 22

    Accepted Solution

    you can just cast it

    Anum = (int)A;

    or convert

    Anum = Convert.ToInt32(A);

    Author Closing Comment

    thanks ;)
    LVL 9

    Expert Comment


    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


    Author Comment

    thanks Dexter anyway

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now