Files
oop/labs/lab9/LearningCenter/Person.cs
2025-09-30 08:21:09 +03:00

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());
}
}