Documentation Center

  • Trial Software
  • Product Updates

When to Use Enumerated Data for Code Generation

You can use enumerated types to represent program states and to control program logic, especially when you need to restrict data to a finite set of values and refer to these values by name. Even though you can sometimes achieve these goals by using integers or strings, enumerated types offer the following advantages:

  • Provide more readable code than integers

  • Allow more robust error checking than integers or strings

    For example, if you mistype the name of an element in the enumerated type, you get a compile-time error that the element does not belong to the set of allowable values.

  • Produce more efficient code than strings

    For example, comparisons of enumerated values execute faster than comparisons of strings.

Was this topic helpful?