Ian MacLean wrote:
how does it throw nothing
This is something borrowed from functional programming -- the delayed execution part, not the no-exception throw. Under the hood, the C# compiler generates a class that implements IEnumerator, containing all captured local variables. Each time foreach is iterated (which corresponds to IEnumerator.MoveNext() method call), the next line would be yielded. Because of this delayed execution, you can pull of some pretty amazing things, such as yielding every even integer without having to allocate an array of size int.Maximum, or yield recursive hierarchies without having to allocate lists, and so on. But it does introduce subtle bugs like the one above.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango