Enum.GetNames in C#



It gets an array of the names of constants in an enumeration. The following is the syntax −

Enum.GetNames(Type)

Here, Type is an enumeration type.

The following is an example −

Example

 Live Demo

using System;

class Demo {
   enum Vehicle {
      Car,
      Motorbike,
      Truck,
   };
   static void Main() {

      // display the enum
      foreach ( string res in Enum.GetNames ( typeof (Vehicle)))
      Console.WriteLine (res);
   }
}

Output

Car
Motorbike
Truck
Updated on: 2020-06-22T13:57:05+05:30

52 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements