dcsimg
Main » TERM » E »

Enumerated Type Definition & Meaning

In programming, an enum, short for enumerated type, is a user-defined data type consisting of a set of named values called enumerators. Instead of using an integer to represent a set of values, a type with a restricted set of values is used instead. Using enums increases the level of abstraction and lets the programmer focus on the value's meaning instead of its storage and accessibility. This, in turn, reduces bugs.

Think of the four suits in a deck of playing cards—clubs, diamonds, hearts, and spades—as four enumerators belonging to an enumerated type named suit. If a variable V is declared having suit as its data type, one can assign any one of those four values (clubs, diamonds, hearts, and spades) to it.

Values and variables of an enum are implemented as fixed-length bit strings that are compatible in format and size with some integer type. In type theory, enums are considered as tagged unions of unit types. Programming languages that use enums include Pascal, Java, and C#.

Enum benefits 

Enums provide the following benefits:

  • They are a constant rather than a number, increasing readability of the source code.
  • They provide compile-time type safety and prevent comparing constants in different enums. A function argument, return type, class member, or local variable can be declared as an enum type and the compiler will enforce type safety.
  • Enums group things into a set.
  • In Java, enumeration can be used as a singleton. A single element enum type is considered one of the best ways to implement a singleton.









LATEST ARTICLES
Texting & Chat Abbreviations

From A3 to ZZZ we list 1,559 text message and online chat abbreviations to help you translate and understand today's texting lingo. Includes Top... Read More »

Huge List of Computer Certifications

Have you heard about a computer certification program but can't figure out if it's right for you? Use this handy list to help you decide. Read More »

STUDY GUIDES
Computer Architecture Study Guide

Computer architecture provides an introduction to system design basics for most computer science students. Read More »

Network Fundamentals Study Guide

Networking fundamentals teaches the building blocks of modern network design. Learn different types of networks, concepts, architecture and... Read More »

The Five Generations of Computers

Learn about each of the five generations of computers and major technology developments that have led to the computing devices that we use... Read More »