# Iterator

The Iterator pattern lets code walk through a collection without knowing how it's stored. In C#, foreach works on anything that implements IEnumerable&lt;T>, which hands out an IEnumerator&lt;T> with MoveNext and Current. Write one by hand to see how it works, then let yield return write it for you.

![Cheat sheet: Iterator](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/311c24790d0c493e8dba15369d2507d9.webp)

- Category: C#
- Level: Journeyman
- Tags: c-sharp, IEnumerable&lt;T>, IEnumerator&lt;T>, Iterator (c-sharp), OOP, Yield Return
- Updated: November 3, 2026

Source: https://www.ask-codey.com/cheat-sheets/design-patterns-iterator-cheat-sheet
