Enum(Enumeration)
- Enumerations offer an easy way to work with sets of related constants.
- An enumeration, or Enum, is a symbolic name for a set of values. Enumerations are treated as data types, and you can use them to create sets of constants for use with variables and properties.
Benefits of using Enumerations
Whenever a procedure accepts a limited set of variables, consider using an enumeration. Enumerations make for clearer and more readable code, particularly when meaningful names are used.When to Use an Enumeration
- Reduces errors caused by transposing or mistyping numbers.
- Makes it easy to change values in the future.
- Makes code easier to read, which means it is less likely that errors will creep into it.
- Ensures forward compatibility. With enumerations, your code is less likely to fail if in the future someone changes the values corresponding to the member names.
Question / Answer
The order of appearance of variables in Enum is their natural order (the natural order means the order in which they are declared inside Enum type).