Convert Enum to Array dynamically in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ProgramEmumtoArray
{
    class ProgramEmumtoArray
    {
        static void Main(string[] args)
        {
            string[] people = Enum.GetNames(typeof(People));
            foreach (var person in people)
            {
                Console.WriteLine(person);
            }
            Console.Read();
        }
 
        enum People
        {
            Gandhi, Anthony, Obama, Mani
        }
 
    }
}

Output:

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.