Enumerators

Enumerators are symbols (like DIME, NICKEL) used to represent values, which values cannot be represented well by other types like int or boolean.

Enumerator types are limited in values (just like how type boolean has only 2 values).

Enumerators are Objects that are set by the compiler to be non-modifiable.

Purpose is for keeping your code readable and therefore less buggy.

 

Enumerator Definition

enum Enumerator
{
     value1, value2, 
}

This creates an enumerator called Enumerator, with values (and only those values).

Enumerators cannot be modified after definition.

Example:

enum Status
{
     SINGLE, MARRIED
}

 

Testing for equals

Enumerators can be tested for equals just like how booleans can, too.

Example:

Status status = Status.SINGLE;
if (status == Status.SINGLE)
     return;
Please like & share: