当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.Sum方法代码示例

本文整理汇总了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);
        }
开发者ID:pixelsyndicate,项目名称:Pro_AspNet_MVC_5_book,代码行数:14,代码来源:UnitTest1.cs

示例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);
 }
开发者ID:olivierdagenais,项目名称:branchreview,代码行数:7,代码来源:AccessibleListViewTest.cs

示例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());
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:TenPinBowlingScorerSuite.cs

示例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));
 }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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));
 }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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));
 }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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);
 }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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));
 }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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));
 }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:SumTests.cs

示例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);
 }
开发者ID:chcosta,项目名称:corefx,代码行数:9,代码来源:SumTests.cs

示例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);
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:TenPinBowlingScorerSuite.cs

示例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());
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:TenPinBowlingScorerSuite.cs

示例15: Calculate

 public Stack<double> Calculate(Stack<double> stack)
 {
     var operands = new[] {stack.Pop(), stack.Pop()};
     stack.Push(operands.Sum());
     return stack;
 }
开发者ID:Murdabenne,项目名称:KSPRPNCalc,代码行数:6,代码来源:Add.cs


注:本文中的System.Collections.Generic.Sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。