Initial Value of an Enum

前端 未结 10 558
陌清茗
陌清茗 2020-12-08 01:51

I have a class with a property which is an enum

The enum is

/// 
/// All available delivery actions
/// 
public enum E         


        
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 02:28

    Best practice (as advised by Code Analysis) is to always have a default value in your enums, which represent an unset value.

    So in your case, you might have:

    public enum EnumDeliveryAction
       {
    
        /// 
        /// Default value
        /// 
        NotSet,
    
        /// 
        /// Tasks with email delivery action will be emailed
        /// 
        Email,
    
        /// 
        /// Tasks with SharePoint delivery action 
       /// 
       SharePoint
      }
    

    As an aside, you shouldn't prefix the name of the enum with Enum. You might consider changing to:

    public enum DeliveryAction;
    

提交回复
热议问题