Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get int values of Enum[]

Tags:

c#

.net

enums

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

like image 917
Jon Avatar asked Feb 13 '26 12:02

Jon


2 Answers

var myInts = channels.Cast<int>();
like image 153
Justin Niessner Avatar answered Feb 15 '26 01:02

Justin Niessner


You can do a cast in the select clause:

var myInts = channels.Select(x => (int)x);
like image 38
Matten Avatar answered Feb 15 '26 01:02

Matten



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!