How to enumerate an enum in C#?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Below is a sample code snippet that demonstrates how to enumerate an enum in C# using Foreach statement?

How to enumerate an enum in C#?

using System;

using System.Collections.Generic;

using System.Data;

namespace AbundantCode

{

internal class Program

{

public enum CodingLanguages

{

CSharp,

Java,

Cplusplus,

HTML

}

// How to Enumerate an enum in C# ?

private static void Main(string[] args)

{

foreach (var languages in Enum.GetValues(typeof(CodingLanguages)))

{

Console.WriteLine(languages);

}

Console.ReadLine();

}

}

}
1
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: