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


C# ICollection.Concat方法代码示例

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


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

示例1: Balance

        public SwapsModel Balance(ICollection<PlayerModel> blueTeam, ICollection<PlayerModel> redTeam)
        {
            if(blueTeam.Count + redTeam.Count != 10)
            {
                throw new ArgumentException("10 players required to balance the teams.");
            }

            int lowestRatingDiff = Int32.MaxValue;
            ICollection<PlayerModel> finalTeam1 = null;
            ICollection<PlayerModel> finalTeam2 = null;

            IList<PlayerModel> players = blueTeam.Concat(redTeam).ToList();
            
            Combinations<PlayerModel> combinations = new Combinations<PlayerModel>(players, 5);

            foreach(ICollection<PlayerModel> team1 in combinations)
            {
                ICollection<PlayerModel> team2 = GetOtherTeam(players, team1);

                int team1Rating = GetTeamRating(team1);
                int team2Rating = GetTeamRating(team2);

                if(Math.Abs(team1Rating - team2Rating) < lowestRatingDiff)
                {
                    lowestRatingDiff = Math.Abs(team1Rating - team2Rating);
                    finalTeam1 = team1;
                    finalTeam2 = team2;
                }
            }

            ICollection<PlayerModel> blueSwaps = CalculateSwaps(blueTeam, finalTeam1, finalTeam2);
            ICollection<PlayerModel> redSwaps = CalculateSwaps(redTeam, finalTeam1, finalTeam2);

            return new SwapsModel()
            {
                RatingDifference = lowestRatingDiff,
                BlueSwaps = blueSwaps,
                RedSwaps = redSwaps
            };
        }
开发者ID:Seaal,项目名称:EloHeaven,代码行数:40,代码来源:BruteForceBalancingStrategy.cs

示例2: SimulateHand

        public static int SimulateHand(ICollection<Card> communityCards, ICollection<Card> playerCards, IList<Card> deck)
        {
            var cardIndex = deck.Count - 1;

            var opponentCards = new List<Card>();
            opponentCards.Add(deck[cardIndex--]);
            opponentCards.Add(deck[cardIndex--]);

            while (communityCards.Count < 5)
            {
                communityCards.Add(deck[cardIndex--]);
            }

            // compare hands
            var betterHand = Helpers.CompareCards(
                    playerCards.Concat(communityCards),
                    opponentCards.Concat(communityCards));
            if (betterHand > 0)
            {
                return 1;
            }

            return 0;
        }
开发者ID:ykomitov,项目名称:TexasHoldem-ColdCall,代码行数:24,代码来源:OddsCalculator.cs

示例3: GetTimelineEnd

        /// <summary>
        /// 获取微博数据结束
        /// </summary>
        /// <param name="tweets"></param>
        private void GetTimelineEnd(ICollection<Status> tweets)
        {
            IsPolling = false;

            isVerticalDrag = false;

            LastPollTime = DateTime.Now;

            Dispatcher.BeginInvoke(() =>
                                       {
                                           var data = (IEnumerable<Status>)FanListBox.ItemsSource;

                                           if (PollType == EPollType.NextPage)
                                           {
                                               data = data.Concat(tweets).ToList();
                                           }
                                           else if (PollType == EPollType.Lastest)
                                           {
                                               tweets = tweets.Where(t => t.Rawid > FirstRawId).ToList();
                                               if (tweets.Count > 0)
                                               {
                                                   data = tweets.Concat(data).ToList();
                                               }
                                           }
                                           else
                                           {
                                               if (tweets != null && tweets.Count > 0)
                                               {
                                                   IsInited = true;
                                               }
                                               data = tweets;
                                           }

                                           if (data != null && data.Any())
                                           {
                                               Status lastOrDefault = data.LastOrDefault();
                                               if (lastOrDefault != null)
                                                   LastRawId = lastOrDefault.Rawid;

                                               Status firstOrDefault = data.FirstOrDefault();
                                               if (firstOrDefault != null)
                                                   FirstRawId = firstOrDefault.Rawid;

                                               Status orDefault = data.FirstOrDefault();
                                               if (orDefault != null)
                                                   FirstId = orDefault.Id;

                                               Status last = data.LastOrDefault();
                                               if (last != null)
                                                   LastId = last.Id;
                                           }

                                           if (FanListBox.ItemTemplate == null)
                                           {
                                               if (ShowType == EShowType.Full)
                                               {
                                                   FanListBox.ItemTemplate =
                                                       (DataTemplate)Resources["FullFanListItemTemplate"];
                                               }
                                               else if (ShowType == EShowType.Reply)
                                               {
                                                   FanListBox.ItemTemplate =
                                                       (DataTemplate)Resources["ReplayListItemTemplate"];
                                               }
                                               else
                                               {
                                                   FanListBox.ItemTemplate =
                                                       (DataTemplate)Resources["SimpleFanListItemTemplate"];
                                               }
                                           }
                                           //处理界面提示

                                           FanListBox.ItemsSource = data;

                                           FanListBox.UpdateLayout();

                                           FanListBox.ShowListFooter = false;

                                           FanListBox.ShowListHeader = false;

                                           if (AfterLoadedCallback != null)
                                           {
                                               AfterLoadedCallback(tweets);
                                           }

                                           if ((PollType == EPollType.Lastest || PollType == EPollType.Default) &&
                                               GotLastest != null)
                                           {
                                               GotLastest();
                                           }
                                       });
        }
开发者ID:chwzou,项目名称:WP7Fanfou,代码行数:96,代码来源:StatusList.xaml.cs

示例4: MemberInitsEqual

        private static bool MemberInitsEqual(ICollection<MemberBinding> bx, ICollection<MemberBinding> by, LambdaExpression rootX, LambdaExpression rootY)
        {
            if (bx.Count != by.Count)
            {
                return false;
            }

            if (bx.Concat(by).Any(b => b.BindingType != MemberBindingType.Assignment))
                throw new NotImplementedException("Only MemberBindingType.Assignment is supported");

            return
                bx.Cast<MemberAssignment>().OrderBy(b => b.Member.Name).Select((b, i) => new { Expr = b.Expression, b.Member, Index = i })
                .Join(
                      by.Cast<MemberAssignment>().OrderBy(b => b.Member.Name).Select((b, i) => new { Expr = b.Expression, b.Member, Index = i }),
                      o => o.Index, o => o.Index, (xe, ye) => new { XExpr = xe.Expr, XMember = xe.Member, YExpr = ye.Expr, YMember = ye.Member })
                       .All(o => Equals(o.XMember, o.YMember) && ExpressionsEqual(o.XExpr, o.YExpr, rootX, rootY));
        }
开发者ID:tocsoft,项目名称:Linq2OData,代码行数:17,代码来源:AssertExpression.cs

示例5: InvokeStepsAsync

        private async Task<RunSummary> InvokeStepsAsync(
            ICollection<IStepDefinition> backGroundStepDefinitions, ICollection<IStepDefinition> scenarioStepDefinitions)
        {
            var filters = this.scenarioClass.Assembly.GetCustomAttributes(typeof(Attribute))
                .Concat(this.scenarioClass.GetCustomAttributes(typeof(Attribute)))
                .Concat(this.scenarioMethod.GetCustomAttributes(typeof(Attribute)))
                .OfType<IFilter<IStepDefinition>>();

            var stepDefinitions = filters
                .Aggregate(
                    backGroundStepDefinitions.Concat(scenarioStepDefinitions),
                    (current, filter) => filter.Filter(current))
                .ToArray();

            var summary = new RunSummary();
            string skipReason = null;
            var teardowns = new List<Action>();
            var stepNumber = 0;
            foreach (var stepDefinition in stepDefinitions)
            {
                stepDefinition.SkipReason = stepDefinition.SkipReason ?? skipReason;

                var stepDisplayName = GetStepDisplayName(
                    this.scenario.DisplayName,
                    ++stepNumber,
                    stepNumber <= backGroundStepDefinitions.Count,
                    stepDefinition.Text,
                    this.scenarioMethodArguments);

                var step = new Step(this.scenario, stepDisplayName);

                var interceptingBus = new DelegatingMessageBus(
                    this.messageBus,
                    message =>
                    {
                        if (message is ITestFailed && stepDefinition.FailureBehavior == RemainingSteps.Skip)
                        {
                            skipReason = string.Format(
                                CultureInfo.InvariantCulture,
                                "Failed to execute preceding step: {0}",
                                step.DisplayName);
                        }
                    });

                var stepRunner = new StepRunner(
                    step,
                    stepDefinition.Body,
                    interceptingBus,
                    this.scenarioClass,
                    this.constructorArguments,
                    this.scenarioMethod,
                    this.scenarioMethodArguments,
                    stepDefinition.SkipReason,
                    new ExceptionAggregator(this.aggregator),
                    this.cancellationTokenSource);

                summary.Aggregate(await stepRunner.RunAsync());
                teardowns.AddRange(stepRunner.Disposables.Select(disposable => (Action)disposable.Dispose)
                    .Concat(stepDefinition.Teardowns.Where(teardown => teardown != null)).ToArray());
            }

            if (teardowns.Any())
            {
                teardowns.Reverse();
                var teardownTimer = new ExecutionTimer();
                var teardownAggregator = new ExceptionAggregator();
                foreach (var teardown in teardowns)
                {
                    teardownTimer.Aggregate(() => teardownAggregator.Run(() => teardown()));
                }

                summary.Time += teardownTimer.Total;

                if (teardownAggregator.HasExceptions)
                {
                    summary.Failed++;
                    summary.Total++;

                    var stepDisplayName = GetStepDisplayName(
                        this.scenario.DisplayName,
                        ++stepNumber,
                        false,
                        "(Teardown)",
                        this.scenarioMethodArguments);

                    this.messageBus.Queue(
                        new Step(this.scenario, stepDisplayName),
                        test => new TestFailed(test, teardownTimer.Total, null, teardownAggregator.ToException()),
                        this.cancellationTokenSource);
                }
            }

            return summary;
        }
开发者ID:mvalipour,项目名称:xbehave.dnx.test,代码行数:94,代码来源:ScenarioInvoker.cs

示例6: CreatePath

        /// <summary>
        /// Creates an instance of <see cref="ODataPath"/> with the given segments.
        /// </summary>
        /// <param name="typeSegments">The type segments seen so far. Will be cleared once they are used in the path.</param>
        /// <param name="lastSegment">The last segment for the path.</param>
        /// <returns>The newly created path.</returns>
        private static ODataPath CreatePath(ICollection<TypeSegment> typeSegments, Segment lastSegment)
        {
            Debug.Assert(typeSegments != null, "typeSegments != null");
            Debug.Assert(lastSegment != null, "lastSegment != null");

            if (typeSegments.Count > 0)
            {
                var path = new ODataPath(typeSegments.Concat(new[] { lastSegment }));
                typeSegments.Clear();
                return path;
            }

            return new ODataPath(lastSegment);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:20,代码来源:SelectBinder.cs


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