Advertisement
sokolova4

Задача 12

Nov 12th, 2020
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace С
  5. {
  6.     class Person
  7.     {
  8.         public string FullName { get; set; }
  9.         public DateTime BirthDate { get; set; }
  10.         public bool IsMale { get; set; }
  11.  
  12.         public virtual void ShowInfo()
  13.         {
  14.             Console.WriteLine($"ФИО {FullName}, Дата рождения {BirthDate}, Пол {(IsMale ? "Мужской" : "Женский")}");
  15.         }
  16.  
  17.  
  18.     }
  19.     class Student : Person
  20.     {
  21.         public string Institute { get; set; }
  22.         public string Speciality { get; set; }
  23.  
  24.         public override void ShowInfo()
  25.         {
  26.             base.ShowInfo();
  27.             Console.WriteLine($"Институт {Institute}, Специальность {Speciality}");
  28.         }
  29.  
  30.         public void NewMethod()
  31.         {
  32.             Console.WriteLine("NewMethod");
  33.         }
  34.     }
  35.  
  36.     class Employee : Person
  37.     {
  38.         public string CompanyName { get; set; }
  39.         public string Post { get; set; }
  40.         public decimal Salary { get; set; }
  41.         public override void ShowInfo()
  42.         {
  43.             base.ShowInfo();
  44.             Console.WriteLine($"Компания {CompanyName}, Должность {Post}, Зарплата {Salary}");
  45.         }
  46.     }
  47.  
  48.     class Program
  49.     {
  50.         static void Main(string[] args)
  51.         {
  52.             Person[] arr= { new Person() { FullName = "Иванов И. И.", BirthDate = DateTime.Now, IsMale = true },
  53.                 new Student() {FullName = "2Иванов И. И.", BirthDate = DateTime.Now, IsMale = true, Institute = "HSE", Speciality="PI"  },
  54.             new Employee() { FullName = "3Иванов И. И.", BirthDate = DateTime.Now, IsMale = true, CompanyName = "R", Post="1",
  55.             Salary = 100000} };
  56.  
  57.             foreach (var item in arr)
  58.             {
  59.                 item.ShowInfo();
  60.                 if(item is Student)
  61.                 {
  62.                     ((Student)item).NewMethod();
  63.                 }
  64.             }
  65.         }
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement