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 by Per C.

quizTest Your Knowledge

How many bits does a VPI header in an ATM cell contain?

A
8
0%
B
10
0%
C
16
0%
D
24
0%
Correct! Incorrect!     View the VPI definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of Enum on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please 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 this definition or would like to suggest a new technical term, please contact us.

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.