Iterators
Using iterators is an alternative to fully implementing IEnumerator or IEnumerable interfaces. Iterators also provide an easier way to implement complex enumerators, such as reverse enumerators. Previously in this chapter, different implementation strategies for enumerators have been shown. There are several options. The enumerator could be implemented as a nested class. A versioned collection could be used. The implementation could be generic or nongeneric. Why should all developers consider these options and implement their rendition of an enumerator? This would not appear to be a good use of their collective mental prowess. Almost assuredly, the various implementations of the enumerator pattern are within an acceptable delta in performance ...
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