/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
using System;
public static class DateTimeExtensions
{
public static int CalculateAge(this DateTime birthDate)
{
DateTime today = DateTime.Today;
int age = today.Year - birthDate.Year;
// Nếu ngày sinh chưa đến trong năm hiện tại, trừ 1 tuổi
if (birthDate.Date > today.AddYears(-age)) age--;
return age;
}
}
class HelloWorld {
static void Main() {
DateTime birthDate = new DateTime(2000, 10, 15);
int age = birthDate.CalculateAge();
Console.WriteLine($"Tuổi hiện tại: {age}");
}
}