Im getting the following error:
Cannot use local variable 'dob' before it is declared
Here is my implementation
public class Person
{
...
public string dob { get; set; }
...
public int getAge()
{
DateTime origin = DateTime.Parse(dob);
return DateTime.Today.Year - origin.Year;
}
public string getFormattedDoB()
{
DateTime origin = DateTime.Parse(dob);
string dob = origin.ToString("d");
return dob;
}
}
I am not sure what to make of this because it is complaining about it's use of dob in getFormattedDoB()
but not in getAge()
which comes before it. If anyone could shed some light on this that would be great
No comments:
Post a Comment