Linq Challenge - Age calculation

we have a string with this format => "Jason Puncheon, 26/06/1986; Jos Hooiveld, 22/04/1983; Kelvin Davis, 29/09/1976; Luke Shaw, 12/07/1995; Gaston Ramirez, 02/12/1990; Adam Lallana, 10/05/1988"

We need to calculate Age foreach one with this format => Jason Puncheon: 23.

// we need to split string by **;** then by sleceted **,** to get list<string[]>
"Jason Puncheon, 26/06/1986; Jos Hooiveld, 22/04/1983; Kelvin Davis, 29/09/1976; Luke Shaw, 12/07/1995; Gaston Ramirez, 02/12/1990; Adam Lallana, 10/05/1988"
.Split(';')
.Select(s => s.Split(','))

image.png

then we need to use tuples or specific class that has name and Age, i'll make this on the fly by anonymous class

/*
"Jason Puncheon, 26/06/1986; Jos Hooiveld, 22/04/1983; Kelvin Davis, 29/09/1976; Luke Shaw, 12/07/1995; Gaston Ramirez, 02/12/1990; Adam Lallana, 10/05/1988"
.Split(';')
.Select(s => s.Split(','))
*/
// anonymous class=> contains Name and Dob(date of birth)
.Select(s => new { Name = s[0].Trim(), Dob = DateTime.ParseExact(s[1].Trim(), "d/M/yyyy", CultureInfo.InvariantCulture) })

image.png

then we need to calculate the Age

static int GetAge(DateTime dateOfBirth)
{
    var today = DateTime.Today;
    int age = today.Year - dateOfBirth.Year;
    if (dateOfBirth > today.AddYears(-age)) age--;
    return age;
}

then the final by using select to show in this format

image.png

// for parsing date
static DateTime ParseDob2(string date) => DateTime.ParseExact(date.Trim(), "d/M/yyyy", CultureInfo.InvariantCulture);

"Jason Puncheon, 26/06/1986; Jos Hooiveld, 22/04/1983; Kelvin Davis, 29/09/1976; Luke Shaw, 12/07/1995; Gaston Ramirez, 02/12/1990; Adam Lallana, 10/05/1988"
.Split(';')
.Select(s => s.Split(','))
.Select(s => new { Name = s[0].Trim(), Dob = ParseDob2(s[1]) })
.OrderByDescending(s => s.Dob)
.Select(s => new { s.Name, Age = GetAge(s.Dob) })
.Select(s => String.Format("{0}: {1}", s.Name, s.Age))