Currently I am trying to calculate the age of someone with a given birthdate, but whenever I run my code the birthdate refactors to the default 01-01-0001.
Birthdate gets set here:
private DateTime BirthDate { get; set; }
This is how i calculate the age of the person:
public int Age
{
get
{
int Age = (int)(DateTime.Today - BirthDate).TotalDays;
Age = Age / 365;
return Age;
}
}
This is the Birthdate I am trying to use:
new DateTime(2000, 3, 12)
But whenever I use the debugger in Visual Studio it gives the birthdate:
01-01-0001
EDIT: This is the rest of the code where I am using the DateTime: This part is in my main class:
Customer cust = new Customer();
cust.VoegToe(new Customer("Lionel Messi", new DateTime(2000, 3, 12), new DateTime(2019, 2, 23)));
This part is in my sub Class:
public Customer()
{
customers = new List<Customer>();
}
public Customer(string name, DateTime BirthDate, DateTime signUpDate)
{
this.name = name;
this.signUpDate = signUpDate;
this.BirthDate= BirthDate;
}
Is there a way to fix this?
Thanks in advance