GetNames() एन्यूमरेशन में स्थिरांक के नामों की सरणी देता है।
निम्नलिखित एनम है।
enum Stock { Watches, Books, Grocery }; नामों की सरणी प्राप्त करने के लिए, GetNames() और लूप थ्रू का उपयोग करें जैसा कि नीचे दिखाया गया है -
foreach(string s in Enum.GetNames(typeof(Stock))) {
} आइए अब पूरा उदाहरण देखें।
उदाहरण
using System;
class Demo {
enum Stock { Watches, Books, Grocery };
static void Main() {
Console.WriteLine("The value of first stock category = {0}",Enum.GetName(typeof(Stock), 0));
Console.WriteLine("The value of second stock category = {0}",Enum.GetName(typeof(Stock), 1));
Console.WriteLine("The value of third stock category = {0}",Enum.GetName(typeof(Stock), 2));
Console.WriteLine("All the categories of stocks...");
foreach(string s in Enum.GetNames(typeof(Stock))) {
Console.WriteLine(s);
}
}
} आउटपुट
The value of first stock category = Watches The value of second stock category = Books The value of third stock category = Grocery All the categories of stocks... Watches Books Grocery