using System.Collections.Generic;
public static void Main(string[] args)
var adults = new List<Adult>
var children = new List<Child>
SchoolName = "Piper Ranch"
SchoolName = "Piper Ranch"
var people = new List<IFirstName>(adults);
people.AddRange(children);
foreach (var person in people)
Console.WriteLine(person.FirstName);
Console.WriteLine("Print all names using an interface\n\n");
foreach (var person in people)
var child = (Child)person;
Console.WriteLine(child.SchoolName);
} else if (person is Adult)
var adult = (Adult)person;
Console.WriteLine(adult.Job);
Console.WriteLine("Print Schools and Job names by using the classes to know the difference\n\n");
PrintFirstNames(children);
Console.WriteLine("Print first names using a generic method\n\n");
var firstNamesUsingConcat = adults.Select(t => t.FirstName).Concat(children.Select(t => t.FirstName)).ToList();
foreach (var firstName in firstNamesUsingConcat)
Console.WriteLine(firstName);
Console.WriteLine("Print first names by concatenating the adults and children lists and selecting only the first names\n\n");
var adultsAndChildrenList = adults.Select(t => t as Person).Concat(children.Select(t => t as Person)).ToList();
foreach (var person in adultsAndChildrenList)
Console.WriteLine(person.FirstName);
Console.WriteLine("Print first names by creating one list of Person by selecting each item from adults and children as a Person\n\n");
private static void PrintFirstNames<T>(List<T> people) where T : Person
foreach (var person in people)
Console.WriteLine(person.FirstName);
public string FirstName { get; set;}
public string LastName { get; set; }
public string Age { get; set; }
public class Child : Person, IFirstName
public string SchoolName { get; set; }
public class Adult : Person, IFirstName
public string Job { get; set; }
public interface IFirstName
string FirstName { get; set; }