Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

The keyword enum introduces an enumerated type, a set of name to integer value associations.

Code Block
enum Python:
     Eric
     John
     TerryG
     TerryJ
     Graham
     Michael

which is equivalent to:

Code Block
enum Python:
     Eric = 0
     John = 1
     TerryG = 2
     TerryJ = 3
     Graham = 4
     Michael = 5

Extracting the integer value of a enum is just a matter of casting it to an int:

Code Block
print((Python.TerryG cast int)*2) # prints 4

Its possible to define partial enums:

Code Block
partial enum E:
    Foo

partial enum E:
    Bar

for value in System.Enum.GetValues(E):
    print value, "=", value cast int