Unity技术分享Unity教程合集

泛型比较

2015-12-17  本文已影响53人  Babybus_Unity
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;
    }

}```
上一篇下一篇

猜你喜欢

热点阅读