C# in Depth

Cover of C# in Depth
Order now (3rd edition)

No code is executed until MoveNext is called

Chapter 6: Implementing iterators the easy way: 6.2.2

Created: 2/24/2008
Last updated: 2/24/2008

I already point this out in the book, but when you call a method or property implemented with an iterator block, none of the code in the body is executed. This can be very confusing - particularly in unit tests!

One reason for including this note when it's already mentioned in the book is that it's a fairly frequently asked question. The other is that Eric has a great blog post about it.