C# এ Type.GetEnumNames() পদ্ধতিটি বর্তমান গণনার প্রকারের সদস্যদের নাম ফেরত দিতে ব্যবহৃত হয়।
সিনট্যাক্স
নিম্নলিখিত সিনট্যাক্স −
public virtual string[] GetEnumNames ();
উদাহরণ
আসুন এখন Type.GetEnumNames() পদ্ধতি প্রয়োগ করার জন্য একটি উদাহরণ দেখি -
using System;
public class Demo {
enum Vehicle {Car, Bus, Bike}
public static void Main(){
try {
Type type = typeof(string);
string[] str = type.GetEnumNames();
Console.WriteLine("GetEnumName() to return the constant name = " + str);
Console.WriteLine("Listing 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
উদাহরণ
এখন Type.GetEnumNames() পদ্ধতি প্রয়োগ করার জন্য আরেকটি উদাহরণ দেখা যাক -
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);
Console.WriteLine("Listing 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[] Listing constants .. Car Bus Bike airplane