Get Max value from List

Assuming you have access to LINQ, and Age is an int (you may also try var maxAge – it is more likely to compile):

int maxAge = myTypes.Max(t => t.Age);

If you also need the RandomID (or the whole object), a quick solution is to use MaxBy from MoreLinq

MyType oldest = myTypes.MaxBy(t => t.Age);

Leave a Comment