Demystifying the C# Yield-Return Mechanism: Listing 4.

Selecting Person objects through filters.

List<Person> list1 = new List<Person>();
foreach (Person p in pList) {
  if (p.Name.StartsWith("A") == true)

List<Person> list2 = new List<Person>();
foreach (Person p in list1) {
  if (p.Age < 20)

foreach (Person p in list2)

About the Author

Dr. James McCaffrey works for Microsoft Research in Redmond, WA. James has worked on several key Microsoft products such as Internet Explorer and Bing. James can be reached at