Can anyone help me why I got error
at least one object must implement icomparable
from this below code?
item.IndicatorMeasurements
.OrderBy(a => a.EntryDateRange.ToDateTime)
.Max()
.Color;
Because you are trying to find the max value of your list of IndicatorMeasurements
, and the compiler has no idea of how to do that. If you want the object with the newest date, you either implement that interface or, more easily, and if the list is not too long, you can use
OrderBy(a => a.EntryDateRange.ToDateTime).Last()
or
OrderByDescending(a => a.EntryDateRange.ToDateTime).First()
.
If the list is long, you should implement that interface or else use your own method to find the maximum item. Thanks Andrey for the hint.
OrderBy
is ineffective for finding the maximum value only
Oct 1, 2015 at 22:41
ToDateTime
sounds like it's a method. Are you sure you didn't intend to call the method? (a => a.EntryDateRange.ToDateTime()
)