2

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

1 Answer 1

6

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.

1
  • 1
    BTW, the solution with OrderBy is ineffective for finding the maximum value only Oct 1, 2015 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.