The simplest example:
IEnumerable<string> GetNames() { yield return "Bob"; yield return "Bob uncle"; yield return "Alice"; yield return "Stacy"; yield return "Stacy mom"; }
Using:
foreach (var name in GetNames()) { Console.WriteLine(name); }
To see it in action, put a debugger breakpoint on each line in the GetNames method.
leppie
source share