public class Utility
{
public static T Max<T>(T x, T y)
{
return (Comparer<T>.Default.Compare(x, y) > 0) ? x : y;
}
public static T Max<T>(params T[] values)
{
T result = values[0];
for (int i = 1; i < values.Length; i++)
result = Max(result, values[i]);
return result;
}
public static T Min<T>(T x, T y)
{
return (Comparer<T>.Default.Compare(x, y) < 0) ? x : y;
}
public static T Min<T>(params T[] values)
{
T result = values[0];
for (int i = 1; i < values.Length; i++)
result = Min(result, values[i]);
return result;
}
}```
网友评论