Пример #1
0
        static void Main(string[] args)
        {
            Person[] persons = new Person[2];
            persons[0] = new Adult("Sukhjeet", "Kaur");
            persons[1] = new Child("Moninder", "Singh");

            foreach (Person p in persons)
            {
                Console.WriteLine(p.FirstName + " " + p.LastName);
            }
        }
Пример #2
0
 static void Main(string[] args)
 {
     Adult[] people = new Adult[2]
     {
         new Child
         {
             FirstName = "Dante",
             LastName  = "Sierkov"
         },
         new Adult
         {
             FirstName = "Serhii",
             LastName  = "Sierkov"
         }
     };
     foreach (var human in people)
     {
         Console.WriteLine($"First Name: {human.FirstName}  Last Name: {human.LastName} Type of record: {human.GetType().Name}");
     }
 }