Returns a bool indicating whether a constant with the specified value exists in the specified enumeration type.
- enumType
- A Type that describes an enumeration.
- value
- The constant or value being searched for in enumType.
- value
- Documentation for this section has not yet been entered.
true if a constant in the enumeration described by enumType has a value equal to value; otherwise, false.
Type Reason ArgumentNullException enumType or value is a null reference. ArgumentException enumType is not an enumeration type.
-or-
The type of value is not an enumType or an underlying type of enumType.
Documentation for this section has not yet been entered.
The following example demonstrates the Enum.IsDefined(Type, object) method.
C# Example
using System; public enum Colors { Red = 1, White = 2, Blue = 4 } public class enumIsDefined { public static void Main() { Console.Write("It is {0} ", Enum.IsDefined(typeof(Colors), 1)); Console.WriteLine("that '1' is defined in 'Colors'."); Console.Write("It is {0} ", Enum.IsDefined(typeof(Colors), 3)); Console.WriteLine("that '3' is defined in 'Colors'."); } }The output is
It is True that '1' is defined in 'Colors'.
It is False that '3' is defined in 'Colors'.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0