views:

117

answers:

2

To convert Enum to Enumerable ,I use

public enum Flags
    {
        Trivial=1,
        Minor,
        Major,
        Critical
    }

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).

+8  A: 
 IEnumerable<Flags> n = Enum.GetValues(typeof(Flags));
Alex Reitbort
A: 

This way you can handle a not sequential enum:

IEnumerable<int> n = 
    Enum.GetValues(typeof(Flags))
        .OfType<Flags>()
        .Select(e => (int)e);
Rubens Farias