Generic overloads for Math.Max etc that take T where T : IComparisonOperators<T, T, bool> #91666
-
There are some very useful methods in the I'm imagining that the source would look something like this: T Max<T>(T left, T right) where T : IComparisonOperators<T, T, bool>
{
return left > right ? left : right;
} Come to think of it, I also don't see generic math implementations for things like *where the implementation would be something like public static R Sum<T, R>(this IEnumerable<T> source)
where T : IAdditiveIdentity<T, R>,
IAdditionOperators<T, R, R>
{
var sum = T.AdditiveIdentity;
foreach(var x in source)
{
sum = x + sum;
}
return sum;
} |
Beta Was this translation helpful? Give feedback.
Answered by
huoyaoyuan
Sep 6, 2023
Replies: 1 comment 4 replies
Answer selected by
Richiban
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#63732