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;
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.