oliverbooth / X10D

Extension methods on crack.
https://oliverbooth.github.io/X10D/
MIT License
27 stars 2 forks source link

IComparable<T> Max and Min #23

Closed oliverbooth closed 3 years ago

oliverbooth commented 3 years ago

Type

System.IComparable<T>

Extension method signature

T Max<T>(T);
T Min<T>(T);
Parameters Parameter Type Description
other T The value to compare against.

Description Returns the maximum/minimum of two values.

Benefits Math.Min() and Math.Max only support primitives and do not support generic comparable types.

Drawbacks None considered (at this time)

(Optional) Implementation example

{
    return value.GreaterThan(other) ? value : other;
    // or
    return value.LessThan(other) ? value : other;
}
oliverbooth commented 3 years ago

Implemented with ac8aead71dff9f14e5dac694e4896fff01f2e714