Retrieving an Enumeration Name with GetName() : Enums Definition : Data Type C# Examples


C# Examples » Data Type » Enums Definition »

 

Retrieving an Enumeration Name with GetName()









    
using  System;
      
public  enum  LegalDoorStates
{
        DoorStateOpen,
        DoorStateClosed
}
      
class  DoorController
{
        private  LegalDoorStates  CurrentState;
      
        public  LegalDoorStates  State
        {
                get
                {
                        return  CurrentState;
                }
      
                set
                {
                        CurrentState  =  value;
                }
        }
}
      
class  MainClass
{
        public  static  void  Main()
        {
                DoorController    Door;
                string                    EnumName;
      
                Door  =  new  DoorController();
      
                Door.State  =  LegalDoorStates.DoorStateOpen;
                EnumName  =  LegalDoorStates.GetName(typeof(LegalDoorStates),  Door.State);
                Console.WriteLine(EnumName);
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Enums Definition