Enum.IsDefined Method (Type, Object)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns an indication whether a constant with a specified value exists in a specified enumeration.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static member IsDefined : 
        enumType:Type *
        value:Object -> bool


Type: System.Type

An enumeration type.

Type: System.Object

The value or name of a constant in enumType.

Return Value

Type: System.Boolean

true if a constant in enumType has a value equal to value; otherwise, false.

Exception Condition

enumType or value is null.


enumType is not an Enum.


The type of value is an enumeration, but it is not an enumeration of type enumType.


The type of value is not an underlying type of enumType.


value is not type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64, or String.

The value parameter can be any of the following:

  • Any member of type enumType.

  • A variable whose value is an enumeration member of type enumType.

  • The string representation of the name of an enumeration member. The characters in the string must have the same case as the enumeration member name.

  • A value of the underlying type of enumType.

If the constants in enumType define a set of bit fields and value contains the values, names, or underlying values of multiple bit fields, the IsDefined method returns false. In other words, for enumerations that define a set of bit fields, the method determines only whether a single bit field belongs to the enumeration. To determine whether multiple bit fields are set in an enumeration type that is tagged with the FlagsAttribute attribute, you can call the HasFlag method.

Notes to Callers:

If enumType is an enumeration that is defined by using the FlagsAttribute attribute, the method returns false if multiple bit fields in value are set but value does not correspond to a composite enumeration value, or if value is a string concatenation of the names of multiple bit flags. In the following example, a Pets enumeration is defined with the FlagsAttribute attribute. The IsDefined method returns false when you pass it an enumeration value that has two bit fields (Pets.Dog and Pets.Cat) set, and when you pass it the string representation of that enumeration value ("Dog, Cat").

No code example is currently available or this language may not be supported.

You can determine whether multiple bit fields are set by calling the HasFlag method.

The following example defines an enumeration named PetType that consists of individual bit fields. It then calls the IsDefined method with possible underlying enumeration values, string names, and composite values that result from setting multiple bit fields.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top