What is the difference between “yield return 0” and “yield return null” in Coroutine?

纵饮孤独 提交于 2019-12-21 03:55:09

问题


I'm new and a bit confused about "yield". But finally I understand how it worked using WaitForSeconds

but I can't see the difference between of "yield return 0" and "yield return null".

are both them waiting for the next frame to execute?

sorry for my bad English. Thank you very much.


回答1:


Both yield return 0 and yield return null yields for a single frame. The biggest difference is that yield return 0 allocates memory because of boxing and unboxing of the 0 that happens under the hood, but yield return null does not allocate memory. Because of this, it is highly recommended to use yield return null if you care about performance.




回答2:


You could even just "yield return;" i think,the end result is the same, regarding the coroutine;

Yield return is like saying "Return control now to the caller, but when i am called again continue from my previous state"



来源:https://stackoverflow.com/questions/39268753/what-is-the-difference-between-yield-return-0-and-yield-return-null-in-corou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!