This post will discuss how to convert an enum to a list in C#.

1. Get a list of Enum members

The idea is to use the Enum.GetValues() method to get an array of the enum constants’ values. To get an IEnumerable<T> of all the values in the enum, call Cast<T>() on the array. To get a list, call ToList() after casting.

Download  Run Code

2. Get an array of Enum members

Instead of using LINQ’s Cast<T>() method, we can cast the array returned by the Enum.GetValues() method, as shown below. The following solution returns an array instead of a list.

Download  Run Code

3. Get a list of Enum members with their constant values

To get a list of enum members with their associated constant values, you can use LINQ’s Select() method, as demonstrated below:

Download  Run Code

4. Get a Dictionary of Enum members with their constant values

To get a Dictionary of enum members with their associated constant values, you can use LINQ’s ToDictionary() method, as demonstrated below:

Download  Run Code

That’s all about converting an enum to a list in C#.