HEIGHT ABOVE SEA LEVEL
  • Articles
  • Quizzes
Join Patreon

Suggested

    Become a Patreon member and receive:

    • 20+ articles ad-free

    • 100+ exclusive videos on C# and how to use Unity

    • 40+ cheat sheets on all things game development

    • 2 Custom Visual Studio Themes

    • 2-day early access to articles and YouTube videos

    Join Patreon
    • Articles
    • Quizzes
    Join Patreon

    Here's some dummy text to automatically resize the container as if there were actual text

    Some dummy text that's hidden to resize the component automatically

    Performance

    Audio

    Become a patreon member and receive the following:

    HEIGHT ABOVE SEA LEVEL
    • Articles
    • Quizzes
    Join Patreon

    Suggested

    • How to Bake Lights in Unity: A Step-by-Step GuideNovember 2, 2025
    • strings header imageA Game Developer's Guide to Strings in C#November 27, 2025
    • A Game Developer's Guide to Loops in C#November 27, 2025
    • A white silhouette of a backyard in Unity.Unity Lights Troubleshooting GuideNovember 2, 2025
    • top youtube channels header imageTop YouTube Channels for Aspiring Unity Game DevelopersNovember 14, 2025

    Become a Patreon member and receive:

    • 20+ articles ad-free

    • 100+ exclusive videos on C# and how to use Unity

    • 40+ cheat sheets on all things game development

    • 2 Custom Visual Studio Themes

    • 2-day early access to articles and YouTube videos

    Join Patreon
    • Articles
    • Quizzes
    Join Patreon

    Question of the Day

    What naming convention is used when naming fields in C#?

    Explanation

    Some people use Camel Case without the underscore, but the convention is to prefix the field with one. For example, private string _firstName.

    Click here to discover more new things about Fields & Properties in C#

    Think you know game dev? Check out the quizzes and find out.

    A Game Developer's Guide to Enums in C#

    A Game Developer's Guide to Enums in C#

    • Beginner C#
    • Set Up & Getting Started
    Victor Nyagudi
    Victor Nyagudi

    November 27, 2025

    Read this article ad-free by becoming a Patreon member

    Enums in C# store related constants. If the game you're building in the Unity Game Engine has seasons or the days of the week, you can store them in an enum.

    Despite storing related constants, enums aren't the same as other types in C# used to store many values, such as lists or arrays. The differences are discussed later in the article.

    If you're a visual learner, scroll to the bottom for the video version, or you can watch it on YouTube.

    How to Use Enums in Unity

    Enums are created in four steps:

    • Write the access modifier.
    • Write the enum keyword.
    • Write the enum's name.
    • Add the enum values separated by commas.

    Access modifiers are discussed in more detail in a separate article, but for now, you can use the public access modifier, meaning the enum is accessible anywhere in your code.

    public enum Season
    {
      Spring,
      Summer,
      Autumn,
      Winter
    }
    
    Debug.Log(Season.Winter); // Logs 'Winter'.

    You can't name the enum using the word "enum" without any modification because that's a special keyword in C#. The values inside an enum are accessed using dot notation.

    Tip

    The word enum is short for enumeration.

    Let's say you want to make a game in Unity where the day of the week is updated every 24 in-game hours, similar to the Grand Theft Auto series. Every in-game Saturday, a random special weapon is available for purchase.

    One approach is to store each day of the week in a string and then check if the current day is Saturday before releasing a special weapon.

    var wednesday = "Wednesday";
    var thursday = "Thursday";
    var friday = "Friday";
    var saturday = "Saturday";
    
    var currentDay = "Tuesday";
    
    if (currentDay == saturday)
      Debug.Log("A new special weapon is available!");

    This could work, but manually typing out the day in each string could lead to typos, a common cause of bugs in many games.

    It's also unclear at a glance whether the strings are related or not because they appear as standalone variables or constants.

    Tip

    The "if" statement in the code above is part of conditional statements.

    Alternatively, you can create an enum and store all the days of the week in it, eliminating the likelihood of introducing typos because each day of the week is typed once.

    In addition, grouping the days of the week in an enum signifies that all the values are connected and shouldn't be seen as individual parts to be used separately.

    public enum DayOfWeek
    {
      Monday,
      Tuesday,
      Wednesday,
      Thursday,
      Friday,
      Saturday,
      Sunday
    }
    
    var currentDay = DayOfWeek.Tuesday;
    
    if (currentDay == DayOfWeek.Saturday)
      Debug.Log("A new special weapon is available!");

    What's the difference between an enum and a list or array in C#?

    Even though enums store values, they're not the same as lists or arrays. Some of the differences are:

    • Enums are declared differently from lists and arrays. They must have the enum keyword.
    • The values stored in an enum are inherently numbers. Lists and arrays can store multiple types, such as strings, numbers, Booleans, etc.
    • You can't loop through an enum, but you can do so with lists and arrays.
    • Enums are named using Pascal Case, while lists and arrays, unless they're constants, are named using Camel Case.
    • Enums can be the only item in a C# file. Lists and arrays are commonly used in files containing other items, such as classes, methods, or fields and properties.

    Despite their similar appearance, you should use an enum if you solely want to group related constants.

    If you have a collection of items you want to manipulate by adding, removing, or updating other items, a list or array is a better choice.

    Recap

    • Enums store related constants.
    • They must be declared using the enum keyword.
    • The values in an enum are inherently numbers.
    • Enum values are accessed using dot notation.
    • Enums, though similar to lists and arrays, are not identical.

    This article is the seventh in a series breaking down common C# concepts used in game development with the Unity Game Engine.

    The next one discusses how to use conditional statements to control the flow of your code's execution.

    Here's the complete list of articles in the series:

    • A Game Developer's Guide to Variables in C#
    • A Game Developer's Guide to Constants in C#
    • A Game Developer's Guide to Numbers in C#
    • A Game Developer's Guide to Operators in C#
    • A Game Developer's Guide to Strings in C#
    • A Game Developer's Guide to Booleans in C#
    • A Game Developer's Guide to Enums in C# (you are here)
    • A Game Developer's Guide to Conditional Statements in C#
    • A Game Developer's Guide to Loops in C#
    • A Game Developer's Guide to Classes in C#
    • A Game Developer's Guide to Access Modifiers in C#
    • A Game Developer's Guide to Fields & Properties in C#
    • A Game Developer's Guide to Methods in C#
    • A Game Developer's Guide to Lists & Arrays in C#
    • A Game Developer's Guide to Dates & Times in C#

    Become a Patreon member and receive:

    • 20+ articles ad-free

    • 100+ exclusive videos on C# and how to use Unity

    • 40+ cheat sheets on all things game development

    • 2 Custom Visual Studio Themes

    • 2-day early access to articles and YouTube videos

    Join Patreon

    Latest

    • A Game Developer's Guide to Classes in C#November 27, 2025
    • A Game Developer's Guide to Loops in C#November 27, 2025
    • A Game Developer's Guide to Conditional Statements in C#November 27, 2025

    Suggested

    • How to Bake Lights in Unity: A Step-by-Step GuideNovember 2, 2025
    • strings header imageA Game Developer's Guide to Strings in C#November 27, 2025
    • A Game Developer's Guide to Loops in C#November 27, 2025
    • A white silhouette of a backyard in Unity.Unity Lights Troubleshooting GuideNovember 2, 2025
    • top youtube channels header imageTop YouTube Channels for Aspiring Unity Game DevelopersNovember 14, 2025

    Become a Patreon member and receive:

    • 20+ articles ad-free

    • 100+ exclusive videos on C# and how to use Unity

    • 40+ cheat sheets on all things game development

    • 2 Custom Visual Studio Themes

    • 2-day early access to articles and YouTube videos

    Join Patreon