返回指定枚举中是否存在具有指定值的常数的指示。
[ComVisibleAttribute(true)] public static bool IsDefined ( Type enumType, Object value )参数
-
enumType
-
枚举类型。
-
value
-
enumType 的常数的值或名称。
返回值
如果 enumType 的某个常数具有等于 value 的值,则为 true;否则为 false。如:
enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
if (Enum.IsDefined(typeof(Days), ds.Tables[0].Rows[0][" Days"].ToString()))
{
model. Days= (Days)int.Parse(ds.Tables[0].Rows[0]["Days"].ToString());
}