Good day. Is it possible to make friends the class I write (inside contains some collection / array) with the For Each loop, as is done in the Collection class? Example:
Dim example As New Collection example.Add 2 example.Add 3 Dim elem As Variant For Each elem In example Debug.Print elem Next elem It can be seen that in example, no function that returns a list of values is explicitly called when a loop is passed to For Each. How can this behavior be implemented for any other type? As I understand it, the language itself uses some kind of service mechanism that implements the concept of an iterator.