Mono Class Library: System.Enum Overview | Members

System.Enum.IsDefined Method

Returns a bool indicating whether a constant with the specified value exists in the specified enumeration type.

[System.Runtime.InteropServices.ComVisible(true)]
public static bool IsDefined (Type enumType, object value)

Parameters

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.

Returns

true if a constant in the enumeration described by enumType has a value equal to value; otherwise, false.

Exceptions

TypeReason
ArgumentNullExceptionenumType 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.

Remarks

Documentation for this section has not yet been entered.

Example

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'.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0