本文介绍了我必须通过填写dateofbirth来自动获得年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经尝试了以下代码并且不知道我必须在哪里传递值,因为该值由用户填充。



我尝试了什么:



  private   static   int  CalculateAge(DateTime DOB)
{
int age = 0 ;
age = DateTime.Now.Year - DOB.Year;

if (DateTime.Now.DayOfYear < DOB.DayOfYear)
age = age - 1 ;

返回年龄;
}

受保护 void Calendar1_SelectionChanged1( object sender,EventArgs e)
{
txtbox2.Text = Calendar1.SelectedDate.ToString();
// int CalculateAge()

Calendar1.Visible = false ;
txtAge.Text = CalculateAge()
}
解决方案




Hi I have tried the below code and dont know where I have to pass this with value because the value is filled by the user.

What I have tried:

private static int CalculateAge(DateTime DOB)
{
    int age = 0;
    age = DateTime.Now.Year - DOB.Year;

    if (DateTime.Now.DayOfYear < DOB.DayOfYear)
      age = age - 1;

    return age;
}

protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
    txtbox2.Text = Calendar1.SelectedDate.ToString();
    //int CalculateAge()

    Calendar1.Visible = false;
    txtAge.Text= CalculateAge()
}
解决方案




这篇关于我必须通过填写dateofbirth来自动获得年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:31