How to determine if a given Integer is in a particular Enum?

后端 未结 4 1603
你的背包
你的背包 2021-02-18 20:13

In VB.NET, even with Option Strict on, it\'s possible to pass an Enum around as an Integer.

In my particular situation, someone\'s using an enum similar to

4条回答
  •  一个人的身影
    2021-02-18 21:03

    One option is to try something like this (in C#):

    bool isTheValueInTheEnum = System.Enum.IsDefined(typeof(Animals), animalType);
    

提交回复
热议问题