The yield return operator is one of the least known among programmers using C#. At least among beginners. And even those who know something about it, are not completely sure that they understand the principle of its work correctly. This annoying gap must be corrected. And, I hope this article will help you with this.
The yield return operator returns the collection item in the iterator and moves the current position to the next element. The presence of the yield return operator turns the method into an iterator. Each time an iterator encounters a yield return, it returns a value.
This operator signals to us and the compiler that this expression is the iterator. The task of the iterator is to move between the elements of the collection and return the value of the current one. Many people are used to call the counter in the loop as an iterator, but this is not true, because the counter does not return a value.
The iterator is converted by the compiler into a "f ...