I am working on a extension method where it finds the min item by specific selector. Below the code
public static T MinBy(this IEnumerable<
IComparable
doesn't provide operator support - you need to use current.CompareTo(min)
. Or better, use Comparer
- then you can drop the constraint and it'll handle nulls etc automatically, and it'll avoid boxing.
var comparer = Comparer.Default;
...
// loop
if(comparer.Compare(current, min) < 0) {...}