The method returns IEnumerable via a yield return statement.
If the yield statement never occurs (it's inside conditional logic), will the method return null, or will it return an Enumerable with a count of 0?
"yield break" breaks the Coroutine (it's similar as "return"). "yield return null" means that Unity will wait the next frame to finish the current scope. "yield return new" is similar to "yield return null" but this is used to call another coroutine.
You use "yield return null;" when you want to skip a frame within that test.
The yield return statement returns one element at a time. The return type of yield keyword is either IEnumerable or IEnumerator . The yield break statement is used to end the iteration. We can consume the iterator method that contains a yield return statement either by using foreach loop or LINQ query.
A valid IEnumerable that produces no values when you iterate through it.
Just think of it: You can store the IEnumerable generator in a variable - the code itself just gets executed when you actually iterate through the results. How could you execute the code if you had null
? Or how did you know the function doesn't yield anything without running it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With