Loading

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

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.Linq in your using section.

posted @ 2017-08-21 19:09  Dhoopu  阅读(141)  评论(0编辑  收藏  举报