I need to get maximum age from array with LINQ.
User[] users = new User[5];
users[0] = new User("Valod", 20, 4, "Electrik");
users[1] = new User("Petros", 25, 9, "Hashvapah");
users[2] = new User("Poghos", 21, 2, "Svarchik");
users[3] = new User("Hakob", 29, 8, "Hashvapah");
users[4] = new User("Karen", 32, 12, "Programmer");
What I have tried:
I tried like this, but it's not working.
var older = from t in users
group t by t.age into s
select new
{
users = s.Max(x => x.age)
};
foreach(User items in older)
{
Console.WriteLine(items.name);
}