Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If yield return never occurs, is null returned?

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?

like image 619
lance Avatar asked Aug 06 '10 19:08

lance


People also ask

Does yield break return null?

"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.

What does yield return NULL do?

You use "yield return null;" when you want to skip a frame within that test.

What does yield return do?

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.


1 Answers

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.

like image 127
Dario Avatar answered Nov 07 '22 09:11

Dario