开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜