I'm trying to build a SelectList
from an Enum
.
Why are the Linq
extension methods not available on Array
?
var values = Enum.GetValues(typeof(MyEnum));
var test = values.Select(x => x); // compile error
But I can write it this way and it compiles...
var test = from Enum e in values select new { e };
I don't normally use this style of syntax so I'm not really familiar with it, but isn't the above essentially the same as the lambda query which doesn't compile?
Use OfType method to get an IEnumerable<T>
that can be queried using LINQ:
var values = Enum.GetValues(typeof(MyEnum));
var test = values.OfType<int>().Select(x => x);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With