欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-04-24 14:19:14
...

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/archive/2012/09/13/2682729.html