How to do it...

  1. In the Chapter1 class, create a new method called OutputInformation() that takes a person object as parameter.
        public void OutputInformation(object person)        {        }
  1. Inside this method, we would need to check what type of object is passed to it. Traditionally, we would need to do the following:
        if (person is Student)        {          Student student = (Student)person;          WriteLine($"Student {student.Name} {student.LastName}                    is enrolled for courses {String.Join<int>(                    ", ", student.CourseCodes)}");        }        if (person is Professor)        {          Professor prof = (Professor)person;          WriteLine($"Professor {prof.Name} {prof.LastName}                     teaches {String.Join<string>(",", prof.TeachesSubjects)}");        }
  1. We have two if statements. We are expecting either a Student object ...

Get C# 7 and .NET Core Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.