Iterators
Technically speaking, iterators are used to step through a collection and iterator functions perform custom iterations over a collection. They can have only an IEnumerable, IEnumerable(Of T), IEnumerator, or IEnumerator(Of T) as their return type. Iterators use the new Yield keyword to return the item that is currently iterated to the caller code; then the iteration stops at that point. After Yield executes, the iteration restarts from that point. With this kind of approach, an iteration over a collection is more responsive and makes items in the collection immediately available to the caller code right after they have been returned. If this technical explanation can seem difficult, let’s provide an easier one. Imagine you have a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access