Just cast it (int)enumVal:


enum BodyType
{
  Fat,
  Thin,
  Musclebound = 500,
  Anorexic
} ;

class Program
{
  static void Main( string[] args )
  {
    BodyType debbie = BodyType.Fat ;
    BodyType john = BodyType.Anorexic ;
    BodyType harold = BodyType.Thin ;

    Console.WriteLine( "Debbie is " + debbie + ".  Numerical value: " + (int)debbie ) ;
    Console.WriteLine( "john is " + john + ".  Numerical value: " + (int)john ) ;
    Console.WriteLine( "harold is " + harold + ".  Numerical value: " + (int)harold ) ;
  }
}

3 Comments

  1. This is not C++

  2. yes it is C#!

  3. My bad. I had tagged it with “C++” accidently – wordpress actually doesn’t let you tag with the # symbol -


Post a Comment