![]() If an enumeration that has the FlagsAttribute applied defines a zero-valued member, its name should be 'None' to indicate that no values have been set in the enumeration. Note that, by default, if the value of the first enumeration member is not set in the declaration, its value is zero. Otherwise, assign zero to the most frequently used member. A non-flagsāattributed enumeration should define a member that has the value of zero so that the default value is a valid value of the enumeration. The default value of an uninitialized enumeration, just like other value types, is zero. The description of the rule is (styling mine): There's a design rule in Visual Studio, CA1008, that provides some insight into your question. I still hold that a None member of a enum can be useful. You would defined it as null using a Nullable value type instead: SomeEnumType? myEnum = null So instead of: var myEnum = SomeEnumType.None The FxCop rule described below existed before Nullable types did. UPDATE: The widely accepted answer on the linked duplicate favors the use of nullable types instead of defining a "null"/"none"/0 member.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
June 2023
Categories |