.NET Development Foundation/Iterators

From Wikibooks, open books for an open world
Jump to: navigation, search

Value Types[edit]

An iterator is a section of code that enables one to tranverse a data structure and return each element of the same type in turn.

The iterator code uses the yield return statement to return each element in turn. When the yield return statement is reached, the current location is stored. Execution is restarted from this location the next time the iterator is called.