- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
charon_ss · Jun 18, 2015 at 06:51 PM ·
ienumerable
Problem with casting List to IEnumerable
I am porting some code written for .net 4.0. This kind of code appears to be invalid for the Unity c# compiler though:
class A { }
class B : A { }
IEnumerable<A> foo() { return new List<B>(); }
Does anybody know a smooth solution to this problem?
Comment
How about IEnumerable<A> foo() { return new List<B>() as IEnumerable<A>; }
?
Your answer
![](https://koobas.hobune.stream/wayback/20220613201127im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Coroutine couldn't be started! [BOO] 2 Answers
Player movement with lerp is jerky. 1 Answer
Flash export: "yield return i;" not supported 1 Answer
Sorting an array of GameObjects by their position 1 Answer
Can I use IENumerable.Repeat in Unity? 0 Answers