Values in Non-Bitwise Enum Types

Question
How should you assign values to non-bitwise enum items?

Answer
Explicitly assign values to non-bitwise entries only when you have special values. For example, error codes with negative values.

Comments
Place special items and their values after regular ones.

Example

public enum ButtonState {
    Visible,
    Disabled,
    Hidden,
    Unknown = -1,
    Invalid = -2
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s