方法:Enum.IsDefined
[Flags]
public
enum
PetType
{
None = 0 , Dog = 1 , Cat = 2 , Rodent = 4 , Bird = 8 , Reptile = 16 , Other = 32
};
object value;
Console.WriteLine( " {0}: {1} " , value, Enum.IsDefined( typeof (PetType), value));
{
None = 0 , Dog = 1 , Cat = 2 , Rodent = 4 , Bird = 8 , Reptile = 16 , Other = 32
};
object value;
Console.WriteLine( " {0}: {1} " , value, Enum.IsDefined( typeof (PetType), value));