Fundamentals
Logic
Expanded to all comparable types
using System; using System.Linq; public class Math { public static T Max<T>(params T[] param) where T : IComparable<T> { return param.Any() ? param.Aggregate(param[0], (a, b) => a.CompareTo(b) > 0 ? a : b) : default; } }
- using System;
- using System.Linq;
- public class Math
- {
public static int Max(params int[] param) => param.Max();- public static T Max<T>(params T[] param)
- where T : IComparable<T>
- {
- return param.Any() ? param.Aggregate(param[0], (a, b) => a.CompareTo(b) > 0 ? a : b) : default;
- }
- }