I have List List
, my type contains Age
and RandomID
Now I want to find the maximum age from this list.
What
How about this way:
List<int> myList = new List<int>(){1, 2, 3, 4}; //or any other type
myList.Sort();
int greatestValue = myList[ myList.Count - 1 ];
You basically let the Sort()
method to do the job for you instead of writing your own method. Unless you don't want to sort your collection.
var maxAge = list.Max(x => x.Age);