Should an Enum start with a 0 or a 1?

前端 未结 14 1415
别那么骄傲
别那么骄傲 2020-12-04 10:19

Imagine I have defined the following Enum:

public enum Status : byte
{
    Inactive = 1,
    Active = 2,
}

What\'s the best practice to use

14条回答
  •  情深已故
    2020-12-04 11:02

    First of all, unless you're specifying specific values for a reason (the numeric value has meaning somewhere else, i.e. The Database or external service) then don't specify numeric values at all and let them be explicit.

    Second of all, you should always have a zero value item (in non-flags enums). That element will be used as the default value.

提交回复
热议问题