Mega Code Archive

 
Categories / C# / Development Class
 

Generic Max Min

using System; using System.Collections.Generic; using System.Linq; using System.Text; public class GenericMaxMin<T> where T : IComparable {     public static T max(params T[] values)     {         T _max;         _max = values[0];         foreach (T _cur in values)         {             if (_cur.CompareTo(_max) > 0)                 _max = _cur;         }         return _max;     }     public static T min(params T[] values)     {         T _max;         _max = values[0];         foreach (T _cur in values)         {             if (_cur.CompareTo(_max) < 0)                 _max = _cur;         }         return _max;     } }