Conversion of Enum to Enumerable
To convert Enum to Enumerable ,I use
public enum Flags
{
Trivial=1,
Minor,
Major,
Criti开发者_如何学Pythoncal
}
IEnumerable<int> n =
Enumerable.Range((int)Flags.Trivial, (int)Flags.Critical).OfType<int>();
Just I want to know whether it is a valid conversion or not (code is working).
This way you can handle a not sequential enum:
IEnumerable<int> n =
Enum.GetValues(typeof(Flags))
.OfType<Flags>()
.Select(e => (int)e);
精彩评论