Unless you have a good reason to use the raw values, you should only ever be using implicit values and referencing them with Status.Active
and Status.Inactive
.
The catch is that you might want to store data in a flat file or DB, or use a flat file or DB that someone else created. If you're making it yourself, make it so the numbering fits what the Enum is used for.
If the data is not yours, of course you're going to want to use whatever the original dev had used as a numbering scheme.
If you're planning on using the Enum as a set of flags, there is a simple convention that's worth following:
enum Example
{
None = 0, // 0
Alpha = 1 << 0, // 1
Beta = 1 << 1, // 2
Gamma = 1 << 2, // 4
Delta = 1 << 3, // 8
Epsilon = 1 << 4, // 16
All = ~0, // -1
AlphaBeta = Alpha | Beta, // 3
}
Values should be powers of two and can be expressed using bit-shift operations. None
, obviously should be 0
, but All
is less obviously -1
. ~0
is the binary negation of 0
and results in a number that has every bit set to 1
, which represents a value of -1
. For compound flags (often used for convenience) other values may be merged using the bitwise or operator |
.