コード例 #1
0
        public void AddMember(Person person)
        {
            if (this.oldestFamilyMember == null || person.Age > this.oldestFamilyMember?.Age)
            {
                this.oldestFamilyMember = person;
            }

            this.people.Add(person);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
 public void AddMember(Person personMember)
 {
     this.People.Add(personMember);
 }