本文整理汇总了C#中System.Collections.Generic.Average方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Average方法的具体用法?C# System.Collections.Generic.Average怎么用?C# System.Collections.Generic.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.Average方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NullableFloat_WithSelector
public void NullableFloat_WithSelector()
{
var source = new []
{
new { name = "Tim", num = (float?)5.5f },
new { name = "John", num = (float?)15.5f },
new { name = "Bob", num = default(float?) }
};
float? expected = 10.5f;
Assert.Equal(expected, source.Average(e => e.num));
}
示例2: NullableDecimal_WithSelector
public void NullableDecimal_WithSelector()
{
var source = new[]
{
new{ name = "Tim", num = (decimal?)5.5m},
new{ name = "John", num = (decimal?)15.5m},
new{ name = "Bob", num = (decimal?)null}
};
decimal? expected = 10.5m;
Assert.Equal(expected, source.Average(e => e.num));
}
示例3: Float_WithSelector
public void Float_WithSelector()
{
var source = new[]
{
new{ name = "Tim", num = 5.5f},
new{ name = "John", num = 15.5f},
new{ name = "Bob", num = 3.0f}
};
float expected = 8.0f;
Assert.Equal(expected, source.Average(e => e.num));
}
示例4: NullableDouble_WithSelector
public void NullableDouble_WithSelector()
{
var source = new[]
{
new{ name = "Tim", num = (double?)5.5 },
new{ name = "John", num = (double?)15.5 },
new{ name = "Bob", num = default(double?) }
};
double? expected = 10.5;
Assert.Equal(expected, source.Average(e => e.num));
}
示例5: Decimal_WithSelector
public void Decimal_WithSelector()
{
var source = new[]
{
new{ name = "Tim", num = 5.5m},
new{ name = "John", num = 15.5m},
new{ name = "Bob", num = 3.0m}
};
decimal expected = 8.0m;
Assert.Equal(expected, source.Average(e => e.num));
}
示例6: Double_WithSelector
public void Double_WithSelector()
{
var source = new []
{
new { name = "Tim", num = 5.5},
new { name = "John", num = 15.5},
new { name = "Bob", num = 3.0}
};
double expected = 8.0;
Assert.Equal(expected, source.Average(e => e.num));
}
示例7: NullableLong_WithSelector
public void NullableLong_WithSelector()
{
var source = new []
{
new { name = "Tim", num = (long?)40L },
new { name = "John", num = default(long?) },
new { name = "Bob", num = (long?)30L }
};
double? expected = 35;
Assert.Equal(expected, source.Average(e => e.num));
}
示例8: Long_FromSelector
public void Long_FromSelector()
{
var source = new []
{
new { name = "Tim", num = 40L },
new { name = "John", num = 50L },
new { name = "Bob", num = 60L }
};
double expected = 50;
Assert.Equal(expected, source.Average(e => e.num));
}
示例9: NullableInt_WithSelector
public void NullableInt_WithSelector()
{
var source = new []
{
new { name = "Tim", num = (int?)10 },
new { name = "John", num = default(int?) },
new { name = "Bob", num = (int?)10 }
};
double? expected = 10;
Assert.Equal(expected, source.Average(e => e.num));
}
示例10: Int_WithSelector
public void Int_WithSelector()
{
var source = new []
{
new { name="Tim", num = 10 },
new { name="John", num = -10 },
new { name="Bob", num = 15 }
};
double expected = 5;
Assert.Equal(expected, source.Average(e => e.num));
}