Practice mode C#

What does the yield return statement do in a C# method?

Correct answer C. It returns one element of an iterator and resumes from that point on the next request

Explanation

A method containing yield return is an iterator returning IEnumerable or IEnumerator. The compiler turns it into a state machine: each time the consumer asks for the next item, execution resumes after the last yield return. Items are produced lazily, so sequences can be infinite. yield break ends the iteration.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.