July 2015
Intermediate to advanced
1300 pages
87h 27m
English
Iterators can be useful in creating classes that act like lists. By implementing the IEnumerable interface and the GetEnumerator method of this interface, you can write efficient code that takes advantage of iterator functions to yield the content of a list. Listing 16.2 demonstrates how to create a class called BottlesOfWine that stores a list of bottles of wine given a name and a color of the wine (red or white). Internally it uses a List(Of BottleOfWine) instance, but instead of invoking the usual GetEnumerator method of the List class (provided by the IEnumerable interface that the List implements), it returns the list of bottles via an iterator function. It also returns a list of bottles based on their color. ...