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. [Edit]

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

Parameters

enumType
A Type that describes an enumeration. [Edit]
value
The constant or value being searched for in enumType. [Edit]
value
Documentation for this section has not yet been entered. [Edit]

Returns

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

Exceptions

TypeReason
ArgumentNullExceptionenumType or value is a null reference. [Edit]
ArgumentException

enumType is not an enumeration type.

-or-

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

[Edit]

Remarks

Documentation for this section has not yet been entered. [Edit]

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