IEnumerable.Cast won’t work even if an explicit cast operator is defined?

Cast operators are static methods that the compiler calls when you use casts in code. They cannot be used dynamically. Enumerable.Cast does a runtime cast of two unconstrained generic types, so it cannot know during compile time which cast operators to use. To do what you want, you can use Select:

manyFoos.Select(foo => (Bar)foo);

Leave a Comment