C# enum contains value

后端 未结 10 672
轮回少年
轮回少年 2020-12-07 23:46

I have an enum

enum myEnum2 { ab, st, top, under, below}

I would like to write a function to test if a given value is included in myEnum

10条回答
  •  生来不讨喜
    2020-12-08 00:27

    What you're doing with ToString() in this case is to:

    Enum.GetValues(typeof(myEnum)).ToString()... instead you should write:

    Enum.GetValues(typeof(myEnum).ToString()...
    

    The difference is in the parentheses...

提交回复
热议问题