forked from ddrilling/AsbCloudServer
56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System;
|
|
|
|
namespace AsbCloudInfrastructure
|
|
{
|
|
public static class Helper
|
|
{
|
|
public static T Max<T>(params T[] items)
|
|
where T : IComparable
|
|
{
|
|
var count = items.Length;
|
|
if (count < 1)
|
|
throw new ArgumentException("Count of params must be greater than 1");
|
|
|
|
var max = items[0];
|
|
for (var i = 1; i < count; i++)
|
|
if (max.CompareTo(items[i]) > 0)
|
|
max = items[i];
|
|
|
|
return max;
|
|
}
|
|
|
|
public static T Min<T>(params T[] items)
|
|
where T : IComparable
|
|
{
|
|
var count = items.Length;
|
|
if (count < 1)
|
|
throw new ArgumentException("Count of params must be greater than 1");
|
|
|
|
var min = items[0];
|
|
for (var i = 1; i < count; i++)
|
|
if (min.CompareTo(items[i]) < 0)
|
|
min = items[i];
|
|
|
|
return min;
|
|
}
|
|
|
|
public static (T min, T max) MinMax<T>(params T[] items)
|
|
where T : IComparable
|
|
{
|
|
var count = items.Length;
|
|
if (count < 1)
|
|
throw new ArgumentException("Count of params must be greater than 1");
|
|
|
|
var min = items[0];
|
|
var max = items[0];
|
|
for (var i = 1; i < count; i++)
|
|
if (max.CompareTo(items[i]) > 0)
|
|
max = items[i];
|
|
else if (min.CompareTo(items[i]) < 0)
|
|
min = items[i];
|
|
|
|
return (min, max);
|
|
}
|
|
}
|
|
}
|