Q:

C# program to demonstrate the IsDefined() method of Enum class

belongs to collection: C# Enum Class Programs

0

C# program to demonstrate the IsDefined() method of Enum class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# program to demonstrate the use of Parse() metho... >>
<< C# program to demonstrate the HasFlag() method of ...