本文整理汇总了C#中System.Collections.Generic.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Sum方法的具体用法?C# System.Collections.Generic.Sum怎么用?C# System.Collections.Generic.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.Sum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_Do_Stuff
public void Can_Do_Stuff()
{
// Arrange - Set up what i`m going to work with
IEnumerable<int> numbers = new[] {0, 1, 2, 3, 4, 5};
// Act - Do the Stuff
var avg = numbers.Sum()/numbers.Count(n => n != 0);
// Assert - Validate it worked
Assert.AreEqual(avg, 3);
Assert.AreEqual(numbers.Sum(), 15);
Assert.IsTrue(numbers.Count() == 6);
Assert.IsTrue(numbers.Count(n => n != 0) == 5);
}
示例2: AdjustWidths_ColumnsThatFitAreUnchanged
public void AdjustWidths_ColumnsThatFitAreUnchanged()
{
var columns = new[] {80, 97, 110, 102};
var sum = columns.Sum();
var actual = AccessibleListView.AdjustWidths(columns, sum);
EnumerableExtensions.EnumerateSame(columns, actual);
}
示例3: MultipleFramesNeverAllPinsDown_GetScore_ShouldReturnSumOfAllPinsDown
public void MultipleFramesNeverAllPinsDown_GetScore_ShouldReturnSumOfAllPinsDown()
{
// Given
var bowlSequence = new[] {4, 4, 4, 4, 4, 4};
ExecuteBowlSequence(bowlSequence);
// When
var score = scorer.GetScore();
// Then
score.Should().Be(bowlSequence.Sum());
}
示例4: SingleFromSelector
public void SingleFromSelector()
{
var source = new[]
{
new { name="Tim", num=9.5f },
new { name="John", num=10.5f },
new { name="Bob", num=3.5f }
};
Assert.Equal(23.5f, source.Sum(e => e.num));
}
示例5: NullableDecimalFromSelector
public void NullableDecimalFromSelector()
{
var source = new[]
{
new { name="Tim", num=(decimal?)20.51m },
new { name="John", num=default(decimal?) },
new { name="Bob", num=(decimal?)2.33m }
};
Assert.Equal(22.84m, source.Sum(e => e.num));
}
示例6: DecimalFromSelector
public void DecimalFromSelector()
{
var source = new[]
{
new {name="Tim", num=20.51m},
new {name="John", num=10m},
new {name="Bob", num=2.33m}
};
Assert.Equal(32.84m, source.Sum(e => e.num));
}
示例7: NullableDoubleFromSelector
public void NullableDoubleFromSelector()
{
var source = new[]
{
new { name="Tim", num=(double?)9.5 },
new { name="John", num=default(double?) },
new { name="Bob", num=(double?)8.5 }
};
Assert.Equal(18.0, source.Sum(e => e.num).Value);
}
示例8: NullableInt64FromSelector
public void NullableInt64FromSelector()
{
var source = new[]{
new { name="Tim", num=(long?)10L },
new { name="John", num=(long?)int.MaxValue },
new { name="Bob", num=default(long?) }
};
Assert.Equal(int.MaxValue + 10L, source.Sum(e => e.num));
}
示例9: Int64FromSelector
public void Int64FromSelector()
{
var source = new[]{
new { name="Tim", num=10L },
new { name="John", num=(long)int.MaxValue },
new { name="Bob", num=40L }
};
Assert.Equal(int.MaxValue + 50L, source.Sum(e => e.num));
}
示例10: NullableInt32FromSelector
public void NullableInt32FromSelector()
{
var source = new[]
{
new { name="Tim", num=(int?)10 },
new { name="John", num=default(int?) },
new { name="Bob", num=(int?)-30 }
};
Assert.Equal(-20, source.Sum(e => e.num));
}
示例11: Int32FromSelector
public void Int32FromSelector()
{
var source = new[]
{
new { name="Tim", num=10 },
new { name="John", num=50 },
new { name="Bob", num=-30 }
};
Assert.Equal(30, source.Sum(e => e.num));
}
示例12: NullableSingleFromSelector
public void NullableSingleFromSelector()
{
var source = new[]{
new { name="Tim", num=(float?)9.5f },
new { name="John", num=default(float?) },
new { name="Bob", num=(float?)8.5f }
};
Assert.Equal(18.0f, source.Sum(e => e.num).Value);
}
示例13: MultipleFramesOneFrameIsSpare_GetScore_ShouldReturnSumOfAllPinsDownPlusFirstBowlAfterSpare
public void MultipleFramesOneFrameIsSpare_GetScore_ShouldReturnSumOfAllPinsDownPlusFirstBowlAfterSpare()
{
// Given
var bowlSequence = new[] {4, 6, 2, 4};
ExecuteBowlSequence(bowlSequence);
// When
var score = scorer.GetScore();
// Then
score.Should().Be(bowlSequence.Sum() + 2);
}
示例14: MultipleFramesOneFrameIsSpareStraddlingFrames_GetScore_ShouldReturnSumOfAllPinsDown
public void MultipleFramesOneFrameIsSpareStraddlingFrames_GetScore_ShouldReturnSumOfAllPinsDown()
{
// Given
var bowlSequence = new[] { 3, 6, 4, 4 };
ExecuteBowlSequence(bowlSequence);
// When
var score = scorer.GetScore();
// Then
score.Should().Be(bowlSequence.Sum());
}
示例15: Calculate
public Stack<double> Calculate(Stack<double> stack)
{
var operands = new[] {stack.Pop(), stack.Pop()};
stack.Push(operands.Sum());
return stack;
}