Assign int value to the first element in an enum : enum base type « Data Type « C# / CSharp Tutorial






enum Planets
{
  Mercury = 1,
  Venus,
  Earth,
  Mars,
  Jupiter,
  Saturn,
  Uranus,
  Neptune,
  Pluto
}

class MainClass
{

  public static void Main()
  {

    System.Console.WriteLine("Position of Earth = " +(int) Planets.Earth);

    System.Console.WriteLine("Planets.Earth = " +Planets.Earth);

  }

}
Position of Earth = 3
Planets.Earth = Earth








2.37.enum base type
2.37.1.Convert enum to int
2.37.2.Assign int value to all elements in an enum
2.37.3.Assign int value to the first element in an enum
2.37.4.Define enumeration base types
2.37.5.Bit Flag Enums
2.37.6.Using Bit flags when declaring the enum
2.37.7.Print out string version of an enum value
2.37.8.Using a base type of long when defining an enum
2.37.9.Using Operators with Enumerations
2.37.10.enum based on byte
2.37.11.enum based on byte, and convert enum variable back to byte