Convert enum to int : Enum base type : Data Type C# Examples


C# Examples » Data Type » Enum base type »

 

Convert enum to int









    
using  System;

enum  Color
{
      Green,
      Yellow,
      Red
}

class  MainClass
{
      static  void  Main()
      {
            Color  t1  =  Color.Green;
            Color  t2  =  Color.Yellow;
            Color  t3  =  Color.Red;

            Console.WriteLine("{0},\t{1}",      t1,  (int)t1);
            Console.WriteLine("{0},\t{1}",      t2,  (int)t2);
            Console.WriteLine("{0},\t{1}\n",  t3,  (int)t3);
      }
}
    
   
  
   



Output

Green,  0
Yellow, 1
Red,    2


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Enum base type