- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to get the type of the specified Enumeration
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.
Example
using System; public class Demo { public static void Main() { Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday}; Console.WriteLine("{0,-5} {1, 10} {2,10}
", "Member", "Enumeration", "UnderlyingType"); foreach (var val in values) Info(val); } 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); } }
Output
Member Enumeration UnderlyingType Blue ConsoleColor Int32 Sunday DayOfWeek Int32
- Related Articles
- Get the underlying type of the current enumeration type C#
- Get the names of the members of the current enumeration type in C#
- Get the specified members of the current Type in C#?
- Get the type referenced by the specified type handle in C#
- Get the handle for the Type of a specified object C#
- C++ Program to get the subarray from an array using a specified range of indices
- Java Program to get name of specified file or directory
- Get the fields of the current Type in C#
- Get the members of the current Type in C#
- Java Program to convert HashSet to Enumeration
- Get Enumeration over HashSet in Java
- C++ program to find the type of the given iterator
- Java Program to get the prime numbers with BigInteger type
- C Program to check the type of character entered
- How to get hash code for the specified key of a Hashtable in C#?

Advertisements