The System.Enum Type : System.Enum : Data Type C# Examples


C# Examples » Data Type » System.Enum »

 

The System.Enum Type









    
using  System;

enum  Color
{
        red,
        green,
        yellow
}

public  class  MainClass
{
        public  static  void  Main()
        {
                Color  c  =  Color.red;
                
                //  enum  values  and  names
                foreach  (int  i  in  Enum.GetValues(c.GetType()))
                {
                        Console.WriteLine("Value:  {0}  ({1})",  i,  Enum.GetName(c.GetType(),  i));
                }
                
        }
}
    
   
  
   



Output

Value: 0 (red)
Value: 1 (green)
Value: 2 (yellow)


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» System.Enum