I'm very new to coding and currently trying to learn C#. As a mini project/ practice I'm trying to create a mini address book, as part of that I want to calculate age from birthDate and today. My code to gather this date is as so:
DateTime today = DateTime.Today;
public int age(DateTime today, DateTime birthDate)
{
if (today.Month < this.birthDate.Month)
{
return ((today.Year - this.birthDate.Year) - 1);
}
else if (today.Month == this.birthDate.Month )
{
if (today.Day >= this.birthDate.Day)
return (today.Year - this.birthDate.Year);
else
return ((today.Year - this.birthDate.Year) - 1);
}
else
return (today.Year - this.birthDate.Year);
}
However when I try to call a Console.WriteLine(person.age)
or do anything with any of my person.age
it tells me
The best overload method match for 'System.Console.WriteLine(string, params object[])' has some invalid arguments.
However as much as i've tried I can't work out what I have done wrong.