The source code to demonstrate the IsDefined() method of Enum class is given below. The given program is compiled and executed successfully.
using System;
class Sample
{
enum Directions { EAST=0,WEST=1,NORTH=2,SOUTH=3};
//Entry point of Program
static public void Main()
{
bool isDefined = false;
isDefined = Directions.IsDefined(typeof(Directions), 1);
if(isDefined==true)
Console.WriteLine("It is defined");
else
Console.WriteLine("It is not defined");
isDefined = Directions.IsDefined(typeof(Directions), 8);
if (isDefined == true)
Console.WriteLine("It is defined");
else
Console.WriteLine("It is not defined");
}
}
Output:
It is defined
It is not defined
Press any key to continue . . .
Program:
The source code to demonstrate the IsDefined() method of Enum class is given below. The given program is compiled and executed successfully.
Output: