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


C# System.Linq.Sum方法代码示例

本文整理汇总了C#中System.Linq.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.Sum方法的具体用法?C# System.Linq.Sum怎么用?C# System.Linq.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Linq的用法示例。


在下文中一共展示了System.Linq.Sum方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public void Execute()
        {
            var numbers = new[]
            {
                1, 2, 3, 4, 5
            };

            //
            // Sum拡張メソッドは、文字通り合計を求める拡張メソッド。
            //
            // Sum拡張メソッドには、各基本型のオーバーロードが用意されており
            // (decimal, double, int, long, single及びそれぞれのNullable型)
            // それぞれに、引数無しとselectorを指定するバージョンのメソッドがある。
            //

            //
            // 引数無しのSum拡張メソッドの使用.
            //
            Output.WriteLine("引数無し = {0}", numbers.Sum());

            //
            // selectorを指定するSum拡張メソッドの使用.
            //
            Output.WriteLine("引数有り = {0}", numbers.Sum(item => item%2 == 0 ? item : 0));
        }
开发者ID:devlights,项目名称:Sazare,代码行数:25,代码来源:LinqSamples33.cs

示例2: TestDistribute

        public void TestDistribute()
        {
            var values = new [] {10d, 70d, 1d}.Distribute(100);
            Assert.AreEqual(100, values.Sum());

            values = new[] { 1d, 1d, 1d }.Distribute(100);
            Assert.AreEqual(100, values.Sum());

            values = new[] { 10d }.Distribute(100);
            Assert.AreEqual(100, values.Sum());

            values = new[] { 100d, 200d }.Distribute(100);
            Assert.AreEqual(100, values.Sum());
        }
开发者ID:webbers,项目名称:dongle.net,代码行数:14,代码来源:EnumerableExtensionsTest.cs

示例3: When_laird_is_defeated_then_all_kobolds_in_hall_are_defeated

        public void When_laird_is_defeated_then_all_kobolds_in_hall_are_defeated()
        {
            // Arrange
            var context = new TestContext();
            var player = context.Player;
            var laird = context.CreateCard<KoboldHumanoid>("Drakeclan Laird");
            var ambusher = context.CreateCard<KoboldHumanoid>("Drakeclan Ambusher");
            var cutter = context.CreateCard<KoboldHumanoid>("Drakeclan Cutter");
            var shaman = context.CreateCard<KoboldHumanoid>("Drakeclan Shaman");
            var kobolds = new[] {laird, ambusher, cutter, shaman};
            context.SetTopOfDungeonDeck(kobolds);
            context.AdvanceMonsterToFirstRank(laird);
            var hand = Enumerable.Range(0, 6).Select(x => context.CreateCard<Criochan>("Criochan Captain")).ToArray();
            context.SetPlayerHand(hand);
            var startingXp = player.Xp;
            var startingVp = player.Vp;

            // Act
            context.WhenBattling(laird);
            player.DetermineBattleResult();

            // Assert
            kobolds.Each(x => Assert.That(player.Discard.Contains(x), "Discard does not contain {0}".Template(x.Name)));
            context.Game.Dungeon.Ranks.Each(r=> Assert.That(r.Card, Is.Not.Null, "Rank {0} is empty".Template(r.Number)));
            kobolds.Each(x => Assert.That(context.Game.Dungeon.Ranks.All(rank => rank.Card != x)));
            Assert.That(player.Xp, Is.EqualTo(startingXp + laird.Xp));
            Assert.That(player.Vp, Is.EqualTo(startingVp + kobolds.Sum(x => x.Vp)));
        }
开发者ID:Slugburn,项目名称:Thunderstone,代码行数:28,代码来源:KoboldHumanoidTest.cs

示例4: GetScore_MultipleFrames_Strike_ShouldReturnSumPlusSumOfTwoBallsAfterStrike

        public void GetScore_MultipleFrames_Strike_ShouldReturnSumPlusSumOfTwoBallsAfterStrike()
        {
            // Arrange
            var bowlSequence = new[] { 10, 4, 3 };
            GivenBowlSequence(bowlSequence);

            // Act
            var score = game.GetScore();

            // Assert
            score.Should().Be(bowlSequence.Sum() + 4 + 3);
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:GameScoringSuite.cs

示例5: GetScore_MultipleFrames_SpareFirstFrame_ShouldReturnSumPlusFirstBallAfterSpare

        public void GetScore_MultipleFrames_SpareFirstFrame_ShouldReturnSumPlusFirstBallAfterSpare()
        {
            // Arrange
            var bowlSequence = new[] { 4, 6, 4, 3 };
            GivenBowlSequence(bowlSequence);

            // Act
            var score = game.GetScore();

            // Assert
            score.Should().Be(bowlSequence.Sum() + 4);
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:GameScoringSuite.cs

示例6: GetScore_MultipleFrames_FourthAndFifthBallAddUpToTenButNoSparesOrStrikes_ShouldReturnSum

        public void GetScore_MultipleFrames_FourthAndFifthBallAddUpToTenButNoSparesOrStrikes_ShouldReturnSum()
        {
            // Arrange
            var bowlSequence = new[] { 3, 6, 4, 3, 7, 2 };
            GivenBowlSequence(bowlSequence);

            // Act
            var score = game.GetScore();

            // Assert
            score.Should().Be(bowlSequence.Sum());
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:GameScoringSuite.cs

示例7: GetScore_MultipleFramesPinsDownLessThanTenEachFrame_ShouldReturnSumOfPinsDown

        public void GetScore_MultipleFramesPinsDownLessThanTenEachFrame_ShouldReturnSumOfPinsDown()
        {
            // Arrange
            var bowlSequence = new[] {4, 5, 4, 3};
            GivenBowlSequence(bowlSequence);

            // Act
            var score = game.GetScore();

            // Assert
            score.Should().Be(bowlSequence.Sum());
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:GameScoringSuite.cs

示例8: MultipleFramesIncludingASpare_GetScore_ShouldReturnSumOfPinsDownPlusBowlAfterSpare

        public void MultipleFramesIncludingASpare_GetScore_ShouldReturnSumOfPinsDownPlusBowlAfterSpare()
        {
            // Arrange
            var bowlSequence = new[] { 6, 4, 4, 4 };
            RunBowlSequence(bowlSequence);

            // Act
            var score = game.GetScore();

            // Assert
            score.Should().Be(bowlSequence.Sum() + 4);
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:GameScoringSuite.cs

示例9: MultipleFramesButNeverAllPinsDown_GetScoreShouldReturnSumOfPinsDown

        public void MultipleFramesButNeverAllPinsDown_GetScoreShouldReturnSumOfPinsDown()
        {
            // Arrange
            var bowlSequence = new[] {4, 4, 4, 4};
            RunBowlSequence(bowlSequence);

            // Act
            var score = game.GetScore();

            // Assert
            score.Should().Be(bowlSequence.Sum());
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:GameScoringSuite.cs

示例10: MultipleFrameFoolsSpareStraddlingFrames_GetScore_ShouldReturnSumOfPinsDown

        public void MultipleFrameFoolsSpareStraddlingFrames_GetScore_ShouldReturnSumOfPinsDown()
        {
            // Arrange
            var bowlSequence = new[] { 4, 4, 6, 4 };
            RunBowlSequence(bowlSequence);

            // Act
            var score = game.GetScore();

            // Assert
            score.Should().Be(bowlSequence.Sum());
        }
开发者ID:christensena,项目名称:TDDIntro,代码行数:12,代码来源:GameScoringSuite.cs


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