I have List List
, my type contains Age
and RandomID
Now I want to find the maximum age from this list.
What
Easiest way is to use System.Linq as previously described
using System.Linq;
public int GetHighestValue(List list)
{
return list.Count > 0 ? list.Max(t => t.Age) : 0; //could also return -1
}
This is also possible with a Dictionary
using System.Linq;
public int GetHighestValue(Dictionary obj)
{
return obj.Count > 0 ? obj.Max(t => t.Key.Age) : 0; //could also return -1
}