Enums
An "enum" is a container for a specific set of constant names that should be referenced by variables. Languages vary in their understanding of how to represent these fixed values, but all can achieve some equivalent.
Start an enum with enum start
, which takes in a PascalCase name of an enum. Ed an enum with enum end
.
Each enum value is declared with enum member
, which takes in a PascalCase name of a member value, an integer value, and if not the last in the enum, a ,
comma.
In C#:
In Python:
Enum types can be treated as their own type in type declarations. Later on, you can reference these enum values using the enum
command, which takes in a name of an enum and a name of one of its values.
In C#:
Direction direction = Direction.Horizontal;
In Python:
direction = Direction.Horizontal
Exports
You can export enums from the current file by including the export
keyword before the enum's name.
In C#:
In Python:
Notes
Enums are fairly non-standard across languages. Don't assume member values to be anything more than a visual suggestion:
Some languages such as C# will sometimes later treat the values as string-likes, such as in string contatenation.
Some languages such as Java will skip printing them altogether.
Last updated