public void AddMember(Person person) { if (this.oldestFamilyMember == null || person.Age > this.oldestFamilyMember?.Age) { this.oldestFamilyMember = person; } this.people.Add(person); }
static void Main(string[] args) { MethodInfo oldestMemberMethod = typeof(Family).GetMethod("GetOldestMember"); MethodInfo addMemberMethod = typeof(Family).GetMethod("AddMember"); if (oldestMemberMethod == null || addMemberMethod == null) { throw new Exception(); } var family = new Family(); var inputCount = int.Parse(Console.ReadLine()); for (int i = 0; i < inputCount; i++) { var parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var person = new Person(parameters[0], int.Parse(parameters[1])); family.AddMember(person); } Console.WriteLine(family.GetOldestMember()); }
public void AddMember(Person personMember) { this.People.Add(personMember); }