Assign int value to all elements in an enum : Enum base type : Data Type C# Examples


C# Examples » Data Type » Enum base type »

 

Assign int value to all elements in an enum









    
enum  PlanetPeriods
{
    Mercury  =  8,
    Venus  =  2,
    Earth  =  3,
    Mars  =  6
}

class  MainClass
{

    public  static  void  Main()
    {
        System.Console.WriteLine("Orbital  period  for  Mars  =  "  +  (int)  PlanetPeriods.Mars  +  "  days");
    }
}
    
   
  
   



Output

Orbital period for Mars = 6 days


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Enum base type