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)
list1.Add(p);
}
List<Person> list2 = new List<Person>();
foreach (Person p in list1) {
if (p.Age < 20)
list2.Add(p);
}
foreach (Person p in list2)
Console.WriteLine(p.ToString());
About the Author
Dr. James McCaffrey directs the data science and research efforts at Quaetrix, a data analytics company located near Redmond, Washington. Before joining Quaetrix, James was a senior research engineer at Microsoft. James can be reached at [email protected].