Here are the examples of the csharp api System.IComparable.CompareTo(TCompare) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
19
Source : Utility.cs
with MIT License
from SardineFish
with MIT License
from SardineFish
public static T MaxOf<T, TCompare>(this IEnumerable<T> ts, Func<T, TCompare> selector)
where TCompare : IComparable<TCompare>
{
var first = true;
TCompare maxValue = default;
T maxItem = default;
foreach (var item in ts)
{
if (first)
{
maxValue = selector(item);
maxItem = item;
first = false;
}
else
{
var value = selector(item);
if (value.CompareTo(maxValue) > 0)
{
maxValue = value;
maxItem = item;
}
}
}
return maxItem;
}
19
Source : Utility.cs
with MIT License
from SardineFish
with MIT License
from SardineFish
public static T MinOf<T, TCompare>(this IEnumerable<T> ts, Func<T, TCompare> selector)
where TCompare : IComparable<TCompare>
{
var first = true;
TCompare minValue = default;
T minItem = default;
foreach (var item in ts)
{
if (first)
{
minValue = selector(item);
minItem = item;
first = false;
}
else
{
var value = selector(item);
if (value.CompareTo(minValue) < 0)
{
minValue = value;
minItem = item;
}
}
}
return minItem;
}