How to enumerate an enum in C#


You can use following code snippet to enumerate an enum in C#

public enum Suit
{
   Spades,
   Hearts,
   Clubs,
   Diamonds
}

foreach (Suit suit in (Suit[])Enum.GetValues(typeof(Suit)))
{
   Console.WriteLine(suit);
}

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments