本文整理汇总了C#中Tuple.Average方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple.Average方法的具体用法?C# Tuple.Average怎么用?C# Tuple.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple.Average方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntegerAverageOnTwoTuple
public void IntegerAverageOnTwoTuple()
{
var sut = new Tuple<int, int>(1, 2);
double expected = sut.AsEnumerable().Cast<int>().Average();
double actual = sut.Average(x => (int) x);
Assert.AreEqual(expected, actual);
}
示例2: DoubleAverageOnTwoTuple
public void DoubleAverageOnTwoTuple()
{
var sut = new Tuple<double, double>(1, 2);
double expected = sut.AsEnumerable().Cast<double>().Average();
double actual = sut.Average(x => (double) x);
Assert.AreEqual(expected, actual);
}
示例3: ShortAverageOnTwoTuple
public void ShortAverageOnTwoTuple()
{
var sut = new Tuple<short, short>(1, 2);
double expected = sut.AsEnumerable().Cast<short>().Average();
double actual = sut.Average(x => (short) x);
Assert.AreEqual(expected, actual);
}
示例4: DecimalAverageOnTwoTuple
public void DecimalAverageOnTwoTuple()
{
var sut = new Tuple<decimal, decimal>(1, 2);
decimal expected = sut.AsEnumerable().Cast<decimal>().Average();
decimal actual = sut.Average(x => (decimal) x);
Assert.AreEqual(expected, actual);
}
示例5: LongAverageOnTwoTuple
public void LongAverageOnTwoTuple()
{
var sut = new Tuple<long, long>(1, 2);
double expected = sut.AsEnumerable().Cast<long>().Average();
double actual = sut.Average(x => (long) x);
Assert.AreEqual(expected, actual);
}
示例6: Avg
public static double Avg(Tuple<double, double>[] weightedValues)
{
if (weightedValues == null || weightedValues.Length == 0)
{
return 0;
}
double totalWeight = weightedValues.Sum(o => o.Item2);
if (Math1D.IsNearZero(totalWeight))
{
return weightedValues.Average(o => o.Item1);
}
double sum = weightedValues.Sum(o => o.Item1 * o.Item2);
return sum / totalWeight;
}