How to check If a Enum contain a number?

后端 未结 4 1389
遥遥无期
遥遥无期 2021-02-02 05:06

I have a Enum like this:

 public enum PromotionTypes
{
    Unspecified = 0, 
    InternalEvent = 1,
    ExternalEvent = 2,
    GeneralMailing = 3,  
    VisitBas         


        
4条回答
  •  独厮守ぢ
    2021-02-02 05:29

    Try this:

    IEnumerable values = Enum.GetValues(typeof(PromotionTypes))
                                  .OfType()
                                  .Select(s => (int)s);
    if(values.Contains(yournumber))
    {
          //...
    }
    

提交回复
热议问题