This iteration returns a value of 3, and the current location in the iterator method is retained. In the following example, the first iteration of the For Each loop causes execution to proceed in the SomeNumbers iterator method until the first Yield statement is reached. You consume an iterator from client code by using a For Each…Next statement, or by using a LINQ query. Execution is restarted from that location the next time the iterator function is called. When a Yield statement is reached, the current location in code is remembered. An iterator method uses the Yield statement to return each element one at a time. An iterator can be used to step through collections such as lists and arrays.Īn iterator method or get accessor performs a custom iteration over a collection.
0 Comments
Leave a Reply. |