DD.WellWorkover.Cloud/AsbCloudInfrastructure/Helper.cs

56 lines
1.5 KiB
C#
Raw Normal View History

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++)
2021-08-25 11:41:09 +05:00
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++)
2021-08-25 11:41:09 +05:00
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++)
2021-08-25 11:41:09 +05:00
if (max.CompareTo(items[i]) < 0)
max = items[i];
2021-08-25 11:41:09 +05:00
else if (min.CompareTo(items[i]) > 0)
min = items[i];
return (min, max);
}
}
}