Q:

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

belongs to collection: C# Enum Class Programs

0

Syntax:

    Type Enum.GetType();

Parameter:

This method does not contain any parameters.

Return value:

This method returns the type of enum of the current object.

 

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 GetType() method of Enum class is given below. The given program is compiled and executed successfully.

using System;

class Sample
{
    enum Colors { RED=0,GREEN=1,YELLOW=3,WHITE=4,BLACK=5};
    enum Directions { EAST,WEST,NORTH,SOUTH};

    //Entry point of Program
    static public void Main()
    {
        string type = "";

        Colors      color       = Colors.RED;
        Directions  direction   = Directions.NORTH;

        type = color.GetType().ToString();
        Console.WriteLine(type);

        type = direction.GetType().ToString();
        Console.WriteLine(type);

    }
}

Output:

Sample+Colors
Sample+Directions
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 GetTypeCode() method... >>
<< C# program to demonstrate the GetNames() method of...