Set initial value for the first element in an enum type in CSharp

Description

The following code shows how to set initial value for the first element in an enum type.

Example


  /*from  w ww. j  a v a2 s .c  o  m*/
  
public class MainClass
{

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

  public static void Main()
  {

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

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

  }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var