“YieldExceptionYield” (Solution)

Answer

Exception is not going to happen.

Explanation

Indeed, the line
1
var numbers = GetSmallNumbers();
Copied!
is only building a query, but does not execute it. The line
1
var evenNumbers = numbers.Select(n => n * 2);
Copied!
is also only building another query without direct execution. Let's look to the last list of the Main method:
1
Console.WriteLine(evenNumbers.FirstOrDefault());
Copied!
This call will get only the first element of the result enumerable (single call of MoveNext() and Current will be executed). Evaluation of the next elements will nor occur. Thus, the code will work without any exceptions.
Problem
Copy link