28 lines
551 B
C#
28 lines
551 B
C#
using System;
|
|
|
|
abstract class Person
|
|
{
|
|
public string LastName { get; }
|
|
public DateTime BirthDate { get; }
|
|
|
|
protected Person(string lastName, DateTime birthDate)
|
|
{
|
|
LastName = lastName;
|
|
BirthDate = birthDate;
|
|
}
|
|
|
|
public int Age()
|
|
{
|
|
var today = DateTime.Today;
|
|
int a = today.Year - BirthDate.Year;
|
|
if (BirthDate.Date > today.AddYears(-a)) a--;
|
|
return a;
|
|
}
|
|
|
|
public virtual void Show()
|
|
{
|
|
Console.WriteLine("{0}, возраст: {1}", LastName, Age());
|
|
}
|
|
}
|
|
|