When does the body of a C# iterator method that uses yield return start running?
Correct answer D. When the caller first calls MoveNext, usually through foreach
Explanation
Calling an iterator method just creates the enumerator object; none of its code runs yet, not even argument checks. Execution begins on the first MoveNext call, such as at the start of a foreach. That is why argument validation in iterators is often moved to a wrapper method or local function, so errors appear at call time.
Answer checked How we write and check questions
Discussion