Let's start with a person class.
class Person
{
public string
FirstName { get; set; }
public string LastName
{ get; set; }
public DateTime Birthdate { get; set; }
public int Age
{
get
{
var today = DateTime.Today;
var age = today.Year - Birthdate.Year;
return Birthdate > today.AddYears(-age) ? --age : age;
}
}
public IEnumerable<DayOfWeek> BirthWeekDays() {
for (int i = 0; i
< this.Age+2; i++)
yield return
Birthdate.AddYears(i).DayOfWeek;
}
public override string
ToString() { return $"{Age} {FirstName} {LastName}"; }
}
so let's see how it goes.
class Program
{
static void Main(string[] args)
{
var p = new Person {
FirstName = "Pawel",
LastName = "Ciucias",
Birthdate = new DateTime(1984, 1, 31)
};
foreach(var wd in p.BirthWeekDays())
Console.WriteLine(wd.ToString());
Console.WriteLine(p.ToString());
}
}