泛型比较

public class Utility
{
    public static T Max(T x, T y)
    {
        return (Comparer.Default.Compare(x, y) > 0) ? x : y;
    }
     public static T Max(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 x, T y)
    {
        return (Comparer.Default.Compare(x, y) < 0) ? x : y;
    }
    public static T Min(params T[] values)
    {
        T result = values[0];
       for (int i = 1; i < values.Length; i++)
       result = Min(result, values[i]);
       return result;
    }

}```

你可能感兴趣的:(泛型比较)