What Are Enums In C#?

Enums are a feature of C# which I commonly use while developing games. The most common use is switching between states.

Vincent Taylor
2 min readOct 28, 2021

Enums:

Enums are a value-type variable that declare a list (not a List<>) of named constants. These constants are keywords which can denote a variety of data in different situations.

By creating another variable of the type of the enum which you just created, you can now assign one of the named constants as the variable value.

This is an easy way to keep track of the current state of a behaviour, entity, or class. It can also dictate what code is executed.

The below code uses a Switch statement to change which code is executes, depending on the current value of “movementState”, the variable of type MovementStates

If the “movementState” variable is “public” or “[SerializeField] private”, then it will appear in the Unity Inspector as a dropdown list, and can be changed to any of the defined constants.

--

--

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.