Should an Enum start with a 0 or a 1?
Framework Design Guidelines:
✔️ DO provide a value of zero on simple enums.
Consider calling the value something like "None." If such a value is not appropriate for this particular enum, the most common default value for the enum should be assigned the underlying value of zero.
Framework Design Guidelines / Designing Flag Enums:
❌ AVOID using flag enum values of zero unless the value represents "all flags are cleared" and is named appropriately, as prescribed by the next guideline.
✔️ DO name the zero value of flag enums None. For a flag enum, the value must always mean "all flags are cleared."
Well, I guess I stand in disagreement with most answers that say not to explicitly number them. I always explicitly number them, but that is because in most cases I end up persisting them in a data stream where they are stored as an integer value. If you don't explicitly add the values and then add a new value you can break the serialization and then not be able to accurately load old persisted objects. If you are going to do any type of persistent store of these values then I would highly recommend explicitly setting the values.
An Enum is a value type and its default value (for example for an Enum field in a class) will be 0 if not initialized explicitly.
Therefore you generally want to have 0 as an defined constant (e.g. Unknown).
In your example, if you want Inactive
to be the default, then it should have the value zero. Otherwise you might want to consider adding a constant Unknown
.
Some people have recommended that you don't explicitly specify values for your constants. Probably good advice in most cases, but there are some cases when you will want to do so:
Flags enums
Enums whose values are used in interop with external systems (e.g. COM).