- Home /
IEnumerable in Unity
That´s right, I´m not asking about IEnumerators, I know how to start a coroutine. The thing is that I have been trying to improve my understanding of yield
in C#, and I noticed that in the microsoft documentation the don´t use IEnumerator
at all when using yield
, in fact it looks to me that they are trying to avoid it to keep things simple.
So, what uses would IEnumerable have in Unity? why is IEnumerator used with yield and not IEnumerable?
Answer by Jessy · Dec 24, 2013 at 02:00 PM
There's nothing special about these interfaces in Unity, aside from Unity using an outdated version of Mono, making them less efficient than we'd all like. I still use IEnumerable a ton, due to LINQ making code shorter and more easily readable. It doesn't make sense to use a garbage collected language for game development, but that's what we've got, so embrace the suck! :-P Alter your code to something more archaic, after profiling, if necessary.
http://www.youtube.com/watch?v=jd3yUjGc9M0
http://stackoverflow.com/questions/619564/what-is-the-difference-between-ienumerator-and-ienumerable
which links to more good answers: http://stackoverflow.com/questions/558304/can-anyone-explain-ienumerable-and-ienumerator-to-me
Despite heavy use of IEnumerable, I never find myself having to implement IEnumerator itself. (These two Interfaces should be generic, with two arrows and a T in the middle, but the site makes them disappear. Please edit this if you know how to bring them back. I never use the non-generic forms.)
I was expecting something special about them, as it happens with IEnumerators. $$anonymous$$aybe I´m wrong but I think we can use IEnumerators as coroutines because they are handled in a special way by the engine (how, otherwise, would null equal one frame?). Any way, good answer! Thank you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613124804im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Corutine not behaving like it should? 1 Answer
IEnumerator does not exist 6 Answers
Increase variable for a few seconds 2 Answers
[ Coroutine: Move Next ] CPU usage 0 Answers
Coroutoutine doesnt work properly. 3 Answers