开发者

Conversion of Enum to Enumerable

开发者 https://www.devze.com 2022-12-11 19:12 出处:网络
To convert Enum to Enumerable ,I use public enum Flags { Trivial=1, Minor, Major, Criti开发者_如何学Pythoncal

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消