I have an enum(below) that I want to be able to use a LINQ extension method on.
enum Suit{
Hearts = 0,
Diamonds = 1,
Clubs = 2,
Spades = 3
}
Enum.GetValues(...) is of return type System.Array, but I can't seem to get access to a ToList() extension or anything else of that sort.
I'm just looking to write something like...
foreach(Suit s in Enum.GetValues(typeof(Suit)).Select(x=>x).Where(x=> x != param)){}
Is there something I'm missing, or can someone explain to me why this isn't possible?
Thanks.
Enum.GetValues
returns aSystem.Array
andSystem.Array
only implementsIEnumerable
rather thanIEnumerable<T>
so you will need to use theEnumerable.OfType
extension method to convert theIEnumerable
toIEnumerable<Suit>
like this:Edit: I removed the call to
IEnumerable.Select
as it was a superfluous projection without any meaningful translation. You can freely filter theIEnumerable<Suit>
that is returned fromOfType<T>
.Array implements IEnumerable so you'll need to use
Cast<Suit>
orOfType<Suit>
to get theIEnumerble<T>
extensions like ToList();