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 ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.