I'm attending an exam at Tuesday in FOOP (described in title), and I've handed in a programme. Problem is that I don't quite understand the following bit. It's a method for calculating a persons age:
public static int CalculateAge(DateTime dob)
{
int years = DateTime.Now.Year - dob.Year;
if ((dob.Month > DateTime.Now.Month) || (dob.Month == DateTime.Now.Month && dob.Day > DateTime.Now.Day))
years--;
return years;
}
I couldn't figure it out myself, so I looked it up on the internet. I don't know what happens inside the if
statement. It should be mentioned that I've a Datetime
variable called dob