[WEBINAR] The New Normal: Dealing with the Reality of an Unsecure World


Definition - What does Enum mean?

Enum, in C#, is a keyword that represents a value type for declaring a set of named constants.

An enum helps to define a series of related integral constants that represent special values within a module of code. An enum can be used in a switch statement, which is used as a decision-making statement for comparing numeric values. It helps to create, maintain and enhance the self-documenting code that needs additional constants in the later versions of the software. An enum is preferred while representing a set of mutually exclusive values. It can be used to represent bitflags and hence can be used to perform logical operations like AND, OR, XOR, etc.

An enum has a better advantage than using integral numeric type because it clearly specifies the range of values that the client code can use, and the values are displayed in the Intellisense of Visual Studio. The use of enums brings the advantage of type safety by assigning the numeric variable in a program with meaningful enum values.

Enum is also called enumeration or an enumerator list.

Techopedia explains Enum

While declaring a value of enum type, the details can include the name, accessibility, underlying type and the names of enum members. The default underlying type, which is a 32-bit integer (int), can be overridden with any integral type (except "char"). The default type of an enum is "int".

For example, an enumeration can be declared to list the months of a year to display in both integer and string form.

The value of an enum member can be assigned explicitly or implicitly. For an enum member that is not assigned explicitly, the first value is set to zero and the members after that each have an associated value that's equal to one more than the value of its predecessor. However, the default values can be overridden by using initializers.

Two members of an enum cannot have the same name but can share the same associated value. The values specified for the members of an enum should be within the range of the underlying type of the enum. The underlying value of an enum member can be obtained by performing an explicit cast to convert it to its integral type.

This definition was written in the context of C#

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
"Techopedia" on Twitter

Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.