C# Enum GetName Method


The GetName() method returns the names of the constants in the Enumeration.

Here is the enum.

enum Stock { Appliance, Clothing, Footwear };

Now, get the names using the Enum.GetName() method. Just set the constant and retrieve the individual name.

Enum.GetName(typeof(Stock), 1

Let us see the example now.

Example

 Live Demo

using System;
class Demo {
   enum Stock { Appliance, Clothing, Footwear };
   static void Main() {
      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));
   }
}

Output

The value of second stock category = Clothing
The value of third stock category = Footwear

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

928 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements