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
returns a System.Array and System.Array
only implements IEnumerable
rather than IEnumerable<T>
so you will need to use the Enumerable.OfType extension method to convert the IEnumerable
to IEnumerable<Suit>
like this:
Enum.GetValues(typeof(Suit))
.OfType<Suit>()
.Where(x => x != param);
Edit: I removed the call to IEnumerable.Select
as it was a superfluous projection without any meaningful translation. You can freely filter the IEnumerable<Suit>
that is returned from OfType<T>
.
Array implements IEnumerable so you'll need to use Cast<Suit>
or OfType<Suit>
to get the IEnumerble<T>
extensions like ToList();