C# 2 and VB.Net 8 introduced a new feature called iterators, which were designed to make it easier to return enumerables and enumerators.
However, iterators are actually a limited form of coroutines, and can be used to do many useful things that have nothing to do with collections of objects.
What non-standard uses of iterators have you seen in real code?
I used them to write a system in ASP.NET for creating a series of linked page interactions. If you imagine a user’s conversation with a website as a series of requests and responses, you can model an interaction as an
IEnumerable. Conceptually, like this;You can store the iterator in session state, so that when the user returns to the site you just pull the iterator out, move the iterator onto the next page, and yield it back for rendering. Complex site interactions are coded in a single place.