I have a method such as:
public void DoIt(params MyEnum[] channels)
{
}
Is there a way to get the int values of the enums in the params?
I tried var myInts = channels.Select(x => x.Value) but no luck
I have a method such as:
public void DoIt(params MyEnum[] channels)
{
}
Is there a way to get the int values of the enums in the params?
I tried var myInts = channels.Select(x => x.Value) but no luck
 
    
    You can do a cast in the select clause:
var myInts = channels.Select(x => (int)x);
 
    
    Another way to do the same, without LINQ:
var vals = Array.ConvertAll(channels, c =>(int)c);
 
    
    var myInts = channels.Select(x=x.Value) this doesn't work because = needs to be => (int)x
I think var myInts = channels.Select(x => (int)x).ToArray(); will do what you want.
 
    
    This should do it:
public void DoIt(params MyEnum[] channels)
{
   int[] ret = channels.Select(x => ((int)x)).ToArray();
}
 
    
    You could do:
var myInts = channels.Select(e => (int)e);
Or as a LINQ query:
var myInts = from e in channels select (int)e;
You could then call ToArray() or ToList() on myInts to get a MyEnum[] or a List<MyEnum>
