Imagine I have defined the following Enum:
public enum Status : byte
{
Inactive = 1,
Active = 2,
}
What's the best practice to use enum? Should it start with 1
like the above example or start with 0
(without the explicit values) like this:
public enum Status : byte
{
Inactive,
Active
}
ベストアンサー1
✔️ 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."