Enum

Enum, short for "enumerated," is a data type that consists of predefined values. A constant or variable defined as an enum can store one of the values listed in the enum declaration.

Enums are used in both source code and database tables. For example, an enum that stores multiple colors may be declared in C# as follows:

enum Color { white, red, green, blue, black };

A column in a MySQL database table may be defined as below:

Color ENUM ('white', 'red', 'green', 'blue', 'black')

A variable or database value defined as Color can be assigned any of the five colors listed in the enum declarations above. If assigned any other value besides the one of the five colors above, it will remain undefined and may produce an error depending on the context. Also, enum variables may only contain one value. If a variable may need to store one or more predefined values, it should be defined as a SET instead.

Enums provide a highly structured way to store data since they can only store a single pre-defined value. While this helps ensure data integrity, it also limits their flexibility. Therefore, enum variables are most appropriate for storing discrete data that can only be one of a few possible values. Examples include colors, sizes, categories, months, and days of the week. Variables that contain more varied data, such as names and places, should be defined as strings.

Updated November 25, 2015

Definitions by TechTerms.com

The definition of Enum on this page is an original TechTerms.com definition. If you would like to reference this page or cite this definition, you can use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about the Enum definition or would like to suggest a new technical term, please contact us.

Want to learn more tech terms? Subscribe to the daily or weekly newsletter and get featured terms and quizzes delivered to your inbox.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.