I have a Enum like this:
public enum PromotionTypes
{
Unspecified = 0,
InternalEvent = 1,
ExternalEvent = 2,
GeneralMailing = 3,
VisitBas
The IsDefined
method requires two parameters. The first parameter is the type of the enumeration to be checked. This type is usually obtained using a typeof expression. The second parameter is defined as a basic object. It is used to specify either the integer value or a string containing the name of the constant to find. The return value is a Boolean that is true if the value exists and false if it does not.
enum Status
{
OK = 0,
Warning = 64,
Error = 256
}
static void Main(string[] args)
{
bool exists;
// Testing for Integer Values
exists = Enum.IsDefined(typeof(Status), 0); // exists = true
exists = Enum.IsDefined(typeof(Status), 1); // exists = false
// Testing for Constant Names
exists = Enum.IsDefined(typeof(Status), "OK"); // exists = true
exists = Enum.IsDefined(typeof(Status), "NotOK"); // exists = false
}
SOURCE