How do I convert an enum to a list in C#? 武胜

This will return an IEnumerable<SomeEnum> of all the values of an Enum.

Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();

If you want that to be a List<SomeEnum>, just add .ToList() after .Cast<SomeEnum>().

To use the Cast function on an Array you need to have the System.System.Linq in your using section.

原文地址:https://www.cnblogs.com/zeroone/p/2682729.html