Enum values in a list

前端 未结 5 1066
悲&欢浪女
悲&欢浪女 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:05

    If you want to get specific enum value from the list user.UserType then you first need to Add enum value to this list:

    var user = new User();
    //1 value - PERMANENT
    user.UserType.Add(USERTYPE.Permanent);
    

    But if you only need to get all the possible values from an arbitrary enum then you can try Enum.GetValues

    //2 values - Permanant and Temporary
    var enums = Enum.GetValues(typeof(USERTYPE));
    

提交回复
热议问题