ここにコードがあります
private void btngetage_Click(object sender, EventArgs e)
{
try
{
string a = txtAge.Text;
DateTime bday = new DateTime(int.Parse(txtbday.Text));
DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if (bday > today.AddYears(-age))
age--;
txtAge.Text = age.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}