Abdalla Omran

Abdalla Omran

  • NA
  • 334
  • 31.6k

How to get the MaxValue using LINQ ?!

Apr 29 2019 7:25 AM
Hi there .
i am useing the following Code trying to get the maxValue from a list but it gives me an Exception (At least one object must implement IComparable) !
I need help to get a solution and explanation why this Exception
Hide Copy Code
public static TheQFromDB GetMaxWithLINQ (List<TheQFromDB> input)
{
TheQFromDB GetItem = input.First();
foreach (var item in input)
{
var max = input.OrderByDescending(s=> s.SecondsDiff).Max();
GetItem = item;
}
return GetItem;
}
 

Answers (3)