It’s always a good idea to use enumerations for properties that have a limited set of valid values, rather than a number. This allows your code to check whether you’re assigning a valid value to the property, and the individual values have easy-to-read names. However, the names you use cannot contain spaces or other non-alphabet […]

This article was posted by Independent Software, a website and database application development company based in Maputo, Mozambique. Our website offers regular write-ups on technical and design issues, ranging from details at code level to 3D Studio Max rendering. Read more about Independent Software's philosophy, or get in touch with Independent Software.

It’s always a good idea to use enumerations for properties that have a limited set of valid values, rather than a number. This allows your code to check whether you’re assigning a valid value to the property, and the individual values have easy-to-read names. However, the names you use cannot contain spaces or other non-alphabet characters, and are limited to the English language (you cannot use characters like á, õ etc.)

Suppose you have the following enumeration:

In other to add human-readable names, possibly in another language, you could add description attributes:

Now, here’s how to access these descriptions in your code:

Usage:

 

Leave a Reply

Your email address will not be published. Required fields are marked *