I noticed that some enumerations have "None" as a enumeration member.
For example what I mean
enum Mode
{
Mode1 = 1,
Mode2 = 2,
Mode3 = 3,
None = 4
}
Why do they use it ? In what cases solution with a none member is more preferable (less preferable) ?
Enumerations make for clearer and more readable code, particularly when meaningful names are used. The benefits of using enumerations include: Reduces errors caused by transposing or mistyping numbers. Makes it easy to change values in the future.
The default value of an uninitialized enumeration, just like other value types, is zero.
Enum ValuesThe first member of an enum will be 0, and the value of each successive enum member is increased by 1. You can assign different values to enum member. A change in the default value of an enum member will automatically assign incremental values to the other members sequentially.
The default value for an enum is zero.
None is important for [Flags]
enums, and should have the value 0. Otherwise... questionable. A Nullable<Mode>
would also suffice. But None
may be demanded for their serialization or ORM layers (it might map to an expected string / int-value etc). Or it might just make the API simpler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With