get all values of enum c# code example
Example 1: loop through an enum c#
public enum Days {
Monday,
Tuesday,
Wednesday
}
foreach(Days day in Enum.GetValues(typeof(Days))) {
}
Example 2: c# get enum in list
Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();
Example 3: c# iterate enum
var values = Enum.GetValues(typeof(Foos));
Example 4: c# get string value of enum
using System;
public class GetNameTest {
enum Colors { Red, Green, Blue, Yellow };
enum Styles { Plaid, Striped, Tartan, Corduroy };
public static void Main() {
Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3));
Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3));
}
}