| Start |
|---|
| Creating Iterators Using Yield Iterators produce enumerators. In C#, enumerators are produced by defining methods, properties or indexers that contain Most methods will return control to their caller through normal This example below demonstrates an iterator method that can be used to generate the Fibonacci sequence (opens new window): This iterator can then be used to produce an enumerator of the Fibonacci sequence that can be consumed by a calling method. The code below demonstrates how the first ten terms within the Fibonacci sequence can be enumerated: Output |
| Simple Numeric Iterator Example A common use-case for iterators is to perform some operation over a collection of numbers. The example below demonstrates how each element within an array of numbers can be individually printed out to the console. This is possible because arrays implement the Output It's also possible to achieve the same results using a RemarksAn iterator is a method, get accessor, or operator that performs a custom iteration over an array or collection class by using the yield keyword |
Read Article
https://develop.horje.com/learn/1434/reference