Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace С
- {
- class Person
- {
- public string FullName { get; set; }
- public DateTime BirthDate { get; set; }
- public bool IsMale { get; set; }
- public virtual void ShowInfo()
- {
- Console.WriteLine($"ФИО {FullName}, Дата рождения {BirthDate}, Пол {(IsMale ? "Мужской" : "Женский")}");
- }
- }
- class Student : Person
- {
- public string Institute { get; set; }
- public string Speciality { get; set; }
- public override void ShowInfo()
- {
- base.ShowInfo();
- Console.WriteLine($"Институт {Institute}, Специальность {Speciality}");
- }
- public void NewMethod()
- {
- Console.WriteLine("NewMethod");
- }
- }
- class Employee : Person
- {
- public string CompanyName { get; set; }
- public string Post { get; set; }
- public decimal Salary { get; set; }
- public override void ShowInfo()
- {
- base.ShowInfo();
- Console.WriteLine($"Компания {CompanyName}, Должность {Post}, Зарплата {Salary}");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Person[] arr= { new Person() { FullName = "Иванов И. И.", BirthDate = DateTime.Now, IsMale = true },
- new Student() {FullName = "2Иванов И. И.", BirthDate = DateTime.Now, IsMale = true, Institute = "HSE", Speciality="PI" },
- new Employee() { FullName = "3Иванов И. И.", BirthDate = DateTime.Now, IsMale = true, CompanyName = "R", Post="1",
- Salary = 100000} };
- foreach (var item in arr)
- {
- item.ShowInfo();
- if(item is Student)
- {
- ((Student)item).NewMethod();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement