Extract information from an enumeration

You can assign the name of a value from an enumeration to a variable. You use dot notation to access the name of the enumeration value.

Before you begin

To create the enumeration that this example uses, you must perform the steps in the following topic:

Procedure

  1. In Studio, in Scratchpad, create a variable that contains an enumeration constant:
    uses doc.example.FruitType
    var myFruitType = FruitType.Banana
  2. Add the following lines to access the properties of the enumeration constant:
    print(myFruitType.Name) // Prints "Banana"
    print(myFruitType.Code) // Prints "Banana"
    print(myFruitType.Ordinal) // Prints "2"
  3. Run the program. The following lines appear in the console:
    Banana
    Banana
    2