निर्दिष्ट गणना में स्थिरांक के मानों की सरणी प्राप्त करें।
यहाँ हमारा एनम है।
enum Rank { Jack = 10, Tom = 19, Tim = 26 };
अब, एनम के सभी मानों को एक सरणी के रूप में प्राप्त करें और GetValues() विधि का उपयोग करके प्रदर्शित करें।
foreach(int res in Enum.GetValues(typeof(Rank))) { Console.WriteLine(res); }
आइए देखें पूरा उदाहरण।
उदाहरण
using System; public class Demo { enum Rank { Jack = 10, Tom = 19, Tim = 26 }; public static void Main() { Console.WriteLine("Here are the university rank of MCA Students College ABC:"); foreach(int res in Enum.GetValues(typeof(Rank))) { Console.WriteLine(res); } } }
आउटपुट
Here are the university rank of MCA Students College ABC: 10 19 26