Enum values in a list

前端 未结 5 1043
悲&欢浪女
悲&欢浪女 2021-02-20 11:38

I\'ve a enum class like,

public enum USERTYPE
{
   Permanant=1,
   Temporary=2,
}

in my business object I just declare this enum as

<         


        
5条回答
  •  春和景丽
    2021-02-20 12:07

    What you have is basically List of enum. Not individual items inside that enum.

    To get list of enum values you can do

    string[] str = Enum.GetNames(typeof(USERTYPE));
    

    To use in get/set return string[] instead of List<>

    public string[] UserType
    {
        get 
        {
            return Enum.GetNames(typeof(USERTYPE));
        }
    }
    

    I think set will not work here because you cannot add values in enum at runtime.

提交回复
热议问题