Home »
.Net »
C# Programs
C# - Enum.GetType() Method with Example
In this tutorial, we will learn about the C# Enum.GetType() method with its definition, usage, syntax, and example.
By Nidhi Last updated : March 29, 2023
C# Enum.GetType() Method
The Enum.GetType() method is used to get the type of enum.
Syntax
Type Enum.GetType();
Parameter(s)
This method does not contain any parameters.
Return Value
This method returns the type of enum of the current object.
C# Example of Enum.GetType() Method
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 . . .
C# Enum Class Programs »