将空值添加到枚举类

时间:2015-06-26 16:46:00

标签: c# wpf

下面是我的代码中可用的enum类,但是,我想为它添加一个空值。将空值添加到此类后,我收到错误。

public enum AgentLevel : int 
{

        [System.Runtime.Serialization.EnumMemberAttribute()]
        Location = 1,

        [System.Runtime.Serialization.EnumMemberAttribute(Value="Head Quarter")]
        HeadQuarter = 2,
}

1 个答案:

答案 0 :(得分:2)

如果您只需要初始化一个空字符串,那么您可以:

public enum AgentLevel : int {

        [System.Runtime.Serialization.EnumMemberAttribute(Value = "")]
        Location = 1,

        [System.Runtime.Serialization.EnumMemberAttribute(Value="Head Quarter")]
        HeadQuarter = 2,
    }