गणना के प्रकार को प्राप्त करने के लिए GetType() विधि का उपयोग करें।
गणना।
Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday}; अब प्रकार प्राप्त करने के लिए, GetType() विधि का उपयोग करें।
Type enumType = val.GetType();
निम्नलिखित एक उदाहरण है जो इस प्रकार को प्रदर्शित करता है।
उदाहरण
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)
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);
}
} आउटपुट
Member Enumeration UnderlyingType Blue ConsoleColor Int32 Sunday DayOfWeek Int32