using System.Collections.Generic;
using System.Linq;
namespace GameDevLibrary.Extensions
{
public static class MathExtensions
{
///
/// Calculate the average value based on a list of values
///
///
///
public static int AverageWithNullValidation(this IEnumerable list)
{
return list.Any() ? (int)list.Average() : 0;
}
///
/// Calculate the average value based on a list of values
///
///
///
public static double AverageWithNullValidation(this IEnumerable list)
{
return list.Any() ? list.Average() : 0.0;
}
///
/// Calculate the average value based on a list of values
///
///
///
public static float AverageWithNullValidation(this IEnumerable list)
{
return list.Any() ? list.Average() : 0.0f;
}
}
}