Collection
zero Useful+1
zero

iterator

Software design pattern
Iterator, sometimes called cursor, is programmed Software design pattern , you can select the container object (container, for example Linked list or array )For the last visited interface, designers need not care about the implementation details of memory allocation of container objects.
Chinese name
iterator
Foreign name
iterator

catalog

Introduction

Announce
edit
Different languages implement iterators in different ways. Some object-oriented languages are like Java , C# , Ruby , Python , Delphi The features of iterators have been built into the language, which is perfectly integrated with the language. We call it implicit iterator, but like C++language, it has no iterator features, but STL still uses Template A powerful iterator is implemented. The memory address of STL container data may be reallocated. The iterator bound to the container can still locate the correct memory address after reallocation.
Iterator can also be integrated generator (generator)。 Some languages regard the two as the same interface, and some languages such as JavaScript Then make it independent. [1]

Example

Announce
edit
C♯
A new form of iterator that provides generator , use yield return [1]
Similar to yield used in Python
// Method that takes an iterable input (possibly an array) // and returns all even numbers. public static IEnumerable<int> GetEven(IEnumerable<int> numbers) {     foreach(int i in numbers)     {         if (i % 2 == 0) yield return i;     } }

See

Announce
edit
C♯