C# enum contains value

后端 未结 10 655
轮回少年
轮回少年 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:39

    Also can use this:

        enum myEnum2 { ab, st, top, under, below }
        static void Main(string[] args)
        {
            myEnum2 r;
            string name = "ab";
            bool result = Enum.TryParse(name, out r);
        }
    

    The result will contain whether the value is contained in enum or not.

提交回复
热议问题