VS2005 中的 C# : can you check whether an integer is declared in a given Enum type?

标签 c# enums

对于 VS2005 中的 C#,有没有办法检查整数是否属于 Enum 类型?

例如:

if number in CustomerType { ... }

在哪里

enum CustomerType
{
    A = 0;
    B = 1;
    C = 2;
}

最佳答案

Enum.IsDefined(Type enumType, Object value)你在找什么?

代替您的 if 语句:

if (Enum.IsDefined(typeof(CustomerType), number))
{
    ...
}

关于VS2005 中的 C# : can you check whether an integer is declared in a given Enum type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3138565/

相关文章:

c# - C# 中的继承和使用覆盖函数 Y() 调用 base.X()

c# - 在 MVC Controller 中加载 XML

c# - 通过文件上传和保存到数据库 asp.net 的多个图像上传

c# - 是否可以将内插字符串作为参数传递给方法?

ios - Objective-c 枚举在 Swift 中获取错误 "... is not convertible to ' NativeObject'"

java - 在构造函数中获取一组枚举并创建列表 - Java

nhibernate - Hibernate/NHibernate 中的枚举表

c# - 远程代码库

python - 如何在数据类模块的 asdict 函数中使用枚举值

sql-server - 您在 SQL Server 中使用什么数据类型进行枚举