কম্পিউটার

C# এ Type.GetEnumUnderlyingType() পদ্ধতি


C#-এ Type.GetEnumUnderlyingType() পদ্ধতিটি বর্তমান গণনার প্রকারের অন্তর্নিহিত প্রকার ফেরত দিতে ব্যবহৃত হয়।

সিনট্যাক্স

নিচের সিনট্যাক্স −

public virtual Type GetEnumUnderlyingType ();

উদাহরণ

আসুন এখন Type.GetEnumUnderlyingType() পদ্ধতি প্রয়োগ করার জন্য একটি উদাহরণ দেখি -

using System;
public class Demo {
   enum Vehicle {Car, Bus, Bike, Airplane}
   public static void Main(){
      try {
         Vehicle v = Vehicle.Bike;
         Type type = v.GetType();
         string[] str = type.GetEnumNames();
         Console.WriteLine("GetEnumName() to return the constant name = " + str);
         Type type2 = type.GetEnumUnderlyingType();
         Console.Write("Enum Underlying type = "+type2);
         Console.WriteLine("\nListing constants ..");
         for (int i = 0; i < str.Length; i++)
            Console.Write("{0} ", str[i]);
      }
      catch (ArgumentException e){
         Console.WriteLine("Not an enum!");
         Console.Write("{0}", e.GetType(), e.Message);
      }
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
GetEnumName() to return the constant name = System.String[]
Enum Underlying type = System.Int32
Listing constants ..
Car Bus Bike Airplane

উদাহরণ

এখন Type.GetEnumUnderlyingType() পদ্ধতি প্রয়োগ করার জন্য আরেকটি উদাহরণ দেখা যাক -

using System;
public class Demo {
   enum Vehicle {Car, Bus, Bike, Airplane}
   public static void Main(){
      try {
         Type type = typeof(int);
         string[] str = type.GetEnumNames();
         Console.WriteLine("GetEnumName() to return the constant name = " + str);
         Type type2 = type.GetEnumUnderlyingType();
         Console.Write("Enum Underlying type = "+type2);
         Console.WriteLine("\nListing constants ..");
         for (int i = 0; i < str.Length; i++)
            Console.Write("{0} ", str[i]);
      }
      catch (ArgumentException e){
         Console.WriteLine("Not an enum!");
         Console.Write("{0}", e.GetType(), e.Message);
      }
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Not an enum!
System.ArgumentException

  1. C# এ Type.GetTypeFromHandle() পদ্ধতি

  2. C# এ Type.GetDefaultMembers() পদ্ধতি

  3. C# এ Type.GetArrayRank() পদ্ধতি

  4. C# এ Type.Equals() পদ্ধতি