C# Program to get the type of the specified Enumeration

CsharpProgrammingServer Side Programming

Use the GetType() method to get the type of the enumeration.

The enumeration.

Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday};

Now to get the type, use the GetType() method.

Type enumType = val.GetType();

The following is an example that displays the type.


 Live Demo

using System;
public class Demo {
   public static void Main() {
      Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday};
      Console.WriteLine("{0,-5} {1, 10} {2,10}\n", "Member", "Enumeration", "UnderlyingType");
      foreach (var val in values)
   static void Info(Enum val) {
      Type enumType = val.GetType();
      Type underlyingType = Enum.GetUnderlyingType(enumType);
      Console.WriteLine("{0, -5} {1, 10} {2,10}", val, enumType.Name, underlyingType.Name);


Member Enumeration UnderlyingType

Blue ConsoleColor Int32
Sunday DayOfWeek Int32
Published on 14-Sep-2018 18:35:14