Get Max() from List<GH_Number>?

Hi all,

i try to get a max and min values from a List<GH_Number> but i get a IComparable error

bool Execute = false;
GH_Structure<GH_Number> Y_Data = new GH_Structure<GH_Number>();

if (!DA.GetData(0, ref Execute)) return;            
if (!DA.GetDataTree(1, out Y_Data)) return;

GH_Number gh_high1 = Y_Data.FlattenData().Max();

System.ArgumentException: β€˜At least one object must implement IComparable.’

I dont understand this error and a tip is welcome.

This is because GH_Number is a wrapped GH_goo class, and .NET does not know how to work out how one GH_Number is bigger than another. To fix this you can put a selector function as an argument to the Linq.Max method. This then returns the largest double, so to get a GH_Number simply build a new GH_number from the max double. Like so:

static GH_Number GetMax(GH_Structure<GH_Number> tree)
{
    return new GH_Number(tree.FlattenData().Max(goo => goo.Value));
}
1 Like