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


C# ICollection.Where方法代码示例

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


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

示例1: GetCardWithSuitThatEnemyDoesNotHave

        public Card GetCardWithSuitThatEnemyDoesNotHave(bool enemyHasATrumpCard, CardSuit trumpSuit, ICollection<Card> playerCards)
        {
            if (!enemyHasATrumpCard)
            {
                // In case the enemy does not have any trump cards and Stalker has a trump, he should throw a trump.
                var myTrumpCards = playerCards.Where(c => c.Suit == trumpSuit).ToList();
                if (myTrumpCards.Count() > 0)
                {
                    return myTrumpCards.OrderBy(c => c.GetValue()).LastOrDefault();
                }
            }

            var orderedCards = playerCards.OrderBy(c => c.GetValue());
            foreach (var card in orderedCards)
            {
                if (this.cardHolder.EnemyCards.All(c => c.Suit != card.Suit))
                {
                    if (enemyHasATrumpCard)
                    {
                        return playerCards.Where(c => c.Suit == card.Suit).OrderBy(c => c.GetValue()).FirstOrDefault();
                    }

                    return playerCards.Where(c => c.Suit == card.Suit).OrderByDescending(c => c.GetValue()).FirstOrDefault();
                }
            }

            return null;
        }
开发者ID:M-Yankov,项目名称:S.T.A.L.K.E.R,代码行数:28,代码来源:StalkerHelper.cs

示例2: Sort

 public IEnumerable<String> Sort(
     ICollection<String> strings)
 {
     return strings
         .Where(item => item.Contains(_keyword))
         .Concat(strings.Where(item => !item.Contains(_keyword)));
 }
开发者ID:Roddoric,项目名称:Monkey.Robotics,代码行数:7,代码来源:TestPreprocessedFiles.cs

示例3: ContainsBlockedEffect

        public static List<int> ContainsBlockedEffect(IWiredItem Box,  ICollection<IWiredItem> Effects)
        {
            List<int> BlockedItems = new List<int>();

            if (Box.Type != WiredBoxType.TriggerRepeat)
                return BlockedItems;

            bool HasMoveRotate = Effects.Where(x => x.Type == WiredBoxType.EffectMoveAndRotate).ToList().Count > 0;
            bool HasMoveNear = Effects.Where(x => x.Type == WiredBoxType.EffectMoveFurniToNearestUser).ToList().Count > 0;

            foreach (IWiredItem Item in Effects)
            {
                if (Item.Type == WiredBoxType.EffectKickUser || Item.Type == WiredBoxType.EffectMuteTriggerer || Item.Type == WiredBoxType.EffectShowMessage || Item.Type == WiredBoxType.EffectTeleportToFurni || Item.Type == WiredBoxType.EffectBotFollowsUserBox)
                {
                    if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId))
                        BlockedItems.Add(Item.Item.GetBaseItem().SpriteId);
                    else continue;
                }
                else if((Item.Type == WiredBoxType.EffectMoveFurniToNearestUser && HasMoveRotate) || (Item.Type == WiredBoxType.EffectMoveAndRotate && HasMoveNear))
                {
                    if (!BlockedItems.Contains(Item.Item.GetBaseItem().SpriteId))
                        BlockedItems.Add(Item.Item.GetBaseItem().SpriteId);
                    else continue;
                }
            }

            return BlockedItems;
        }
开发者ID:BjkGkh,项目名称:Boon,代码行数:28,代码来源:WiredBoxTypeUtility.cs

示例4: TripModel

 public TripModel(Trip trip, ICollection<Auto> autos, ICollection<Employee> employees)
 {
     this.tripNumber = trip.NumberTrip;
     this.name = (employees.Where(x => x.EmployeeId == trip.EmployeeId).FirstOrDefault()).Name;
     this.secondName = (employees.Where(x => x.EmployeeId == trip.EmployeeId).FirstOrDefault()).SecondName;
     this.depNumber = (autos.Where(x => x.AutoId == trip.AutoId).FirstOrDefault()).DepNumber;
     this.startDate = trip.StartDate;
     this.endDate = trip.EndDate;
 }
开发者ID:sjkrypa,项目名称:iTrips,代码行数:9,代码来源:TripModel.cs

示例5: EventBatchProcessingAsync

        public override async Task EventBatchProcessingAsync(ICollection<EventContext> contexts) {
            var autoSessionEvents = contexts
                .Where(c => c.Event.GetUserIdentity()?.Identity != null
                    && String.IsNullOrEmpty(c.Event.GetSessionId())).ToList();

            var manualSessionsEvents = contexts
                .Where(c => !String.IsNullOrEmpty(c.Event.GetSessionId())).ToList();
            
            await ProcessAutoSessionsAsync(autoSessionEvents).AnyContext();
            await ProcessManualSessionsAsync(manualSessionsEvents).AnyContext();
        }
开发者ID:yonglehou,项目名称:Exceptionless,代码行数:11,代码来源:70_SessionPlugin.cs

示例6: GetNonGroupedAssets

    /// <summary>
    /// Gets assets that are either available over a CDN or are not in any group
    /// </summary>
    /// <param name="assets"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    ICollection<Asset> GetNonGroupedAssets(ICollection<Asset> assets, AssetType type)
    {
      var nonGrouped = assets.Where(a => a.AssetType == type && a.Group == Asset.NoGroup);

      if (Settings.Default.UseCDN)
      {
        return nonGrouped.Concat(assets.Where(a => a.AssetType == type && a.Group != Asset.NoGroup &&
          GetCdnUrl(a.Name) != null)).Distinct().ToList();
      }
      return nonGrouped.Distinct().ToList();
    }
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:17,代码来源:AssetService.cs

示例7: buildLogInfos

 public static ICollection<LoginInfo> buildLogInfos(ICollection<MLogInfo> mLogInfos, ICollection<LoginInfo> logInfos)
 {
     // TODO: fixed HashSet definition taken from Person entity
     foreach (LoginInfo li in logInfos)
     {
         // only password and login name can be changed
         li.password =  mLogInfos.Where(mli => mli.ID == li.Id).FirstOrDefault().Password;
         li.name = mLogInfos.Where(mli => mli.ID == li.Id).FirstOrDefault().LoginName;
     }
     return logInfos;
 }
开发者ID:Dadov,项目名称:3rdsemproject,代码行数:11,代码来源:DLogInfo.cs

示例8: ChooseCardToPlay

        public Card ChooseCardToPlay(PlayerTurnContext context, ICollection<Card> stalkerCards)
        {
            var trumpSuit = context.TrumpCard.Suit;
            var highestPrioritySuit = 0;
            var priorityValue = int.MaxValue;

            // Get priorities for all suits
            var suitsPriorities = this.GetPriorityForEachSuit(context);

            // Check which suits are available
            var availableSuits = new int[4];
            foreach (var card in stalkerCards)
            {
                var suit = (int)card.Suit;
                availableSuits[suit]++;
            }

            for (var i = 0; i < suitsPriorities.Length; i++)
            {
                if ((int)trumpSuit == i || availableSuits[i] == 0)
                {
                    continue;
                }

                if (suitsPriorities[i] < priorityValue)
                {
                    highestPrioritySuit = i;
                    priorityValue = suitsPriorities[i];
                }
            }

            // Select the cards from the best suit
            var cardsFromBestSuit = stalkerCards.Where(card => card.Suit == (CardSuit)highestPrioritySuit).OrderBy(this.stalkerHelper.GetCardPriority).ToList();
            var cardsFromTrump = stalkerCards.Where(card => card.Suit == trumpSuit).OrderBy(this.stalkerHelper.GetCardPriority).ToList();

            if (!context.State.ShouldObserveRules)
            {
                // Take all nontrump cards without Queen and King waiting for announce
                cardsFromBestSuit = stalkerCards.Where(c => c.Suit != trumpSuit && !(this.stalkerHelper.GetCardPriority(c) == 1 && this.IsCardWaitingForAnnounce(c))).OrderBy(this.stalkerHelper.GetCardPriority).ToList();
            }

            // Sort cards by its priority
            var cardsToChooseFrom = cardsFromBestSuit.Count != 0 ? cardsFromBestSuit : cardsFromTrump;

            if (!context.State.ShouldObserveRules)
            {
                // THIS NUMBER WILL AFFECT THE DECISION OF THE STALKER WHEN IN OPEN STATE
                return priorityValue > CardChooserConstants.OpenGamePriority ? cardsToChooseFrom.LastOrDefault() : cardsToChooseFrom.FirstOrDefault();
            }

            // THIS NUMBER WILL AFFECT THE DECISION OF THE STALKER WHEN IN CLOSED STATE
            return priorityValue < CardChooserConstants.ClosedGamePriority ? cardsToChooseFrom.LastOrDefault() : cardsToChooseFrom.FirstOrDefault();
        }
开发者ID:M-Yankov,项目名称:S.T.A.L.K.E.R,代码行数:53,代码来源:CardChooser.cs

示例9: GetChairNumbers

        public static List<string> GetChairNumbers(int[] chirsOrderdID,ICollection<ChairsOrderd> ChairsOrder )
        {
            HomeCinemaContext db = new HomeCinemaContext();

            List<string> ChairsNumber = new List<string>();

                for (int i = 0; i < chirsOrderdID.Length; i++)
                {
                    var row =  db.Rows.Find(ChairsOrder.Where(x => chirsOrderdID[i] == x.ChairsOrderdiD).First().HallChairs.RowID);
                    ChairsNumber.Add(string.Format(row.RowNumber.ToString()
                        +":"+ChairsOrder.Where(x => chirsOrderdID[i] == x.ChairsOrderdiD).First().HallChairs.ChairNumber.ToString()));
                }
            return ChairsNumber;
        }
开发者ID:ZivDaniel12,项目名称:Mvc-Project-Cinema-City,代码行数:14,代码来源:EcomLogic.cs

示例10: BuildTableList

        private static string[] BuildTableList(ICollection<string> allTables, ICollection<Relationship> allRelationships)
        {
            var tablesToDelete = new List<string>();

            while (allTables.Any())
            {
                string[] leafTables = allTables.Except(allRelationships.Select(rel => rel.PrimaryKeyTable)).ToArray();

                if(leafTables.Length == 0)
                {
                    tablesToDelete.AddRange(allTables);
                    break;
                }

                tablesToDelete.AddRange(leafTables);

                foreach (string leafTable in leafTables)
                {
                    allTables.Remove(leafTable);
                    Relationship[] relToRemove =
                        allRelationships.Where(rel => rel.ForeignKeyTable == leafTable).ToArray();
                    foreach (Relationship rel in relToRemove)
                    {
                        allRelationships.Remove(rel);
                    }
                }
            }

            return tablesToDelete.ToArray();
        }
开发者ID:fyulnady,项目名称:CMBootCamp,代码行数:30,代码来源:DatabaseEmptier.cs

示例11: SubstractApprovedQuantityFromStock

 private static void SubstractApprovedQuantityFromStock(ICollection<StockInformation> stock, ICollection<ApprovedDetail> approvedDetails)
 {
     approvedDetails = approvedDetails.Where(s=>s.Quantity > 0).OrderBy(s => s.Priority).ToList();
     foreach (var approvedDetail in approvedDetails)
     {
         var stockInformations =
             stock.Where(
                 s =>
                 ((approvedDetail.ActivityGroup == null ||
                   approvedDetail.ActivityGroup.ActivityGroupID == s.Activity.ActivityGroupID)
                  &&
                  ((approvedDetail.Manufacturer == null) ||
                   (approvedDetail.Manufacturer.ManufacturerID == s.Manufacturer.ManufacturerID))
                  &&
                  (approvedDetail.physicalStore == null ||
                   (approvedDetail.physicalStore.PhysicalStoreID == s.PhysicalStore.PhysicalStoreID))
                  && (approvedDetail.ExpiryDate == null || approvedDetail.ExpiryDate == s.ExpiryDate))).ToList();
         var i = 0;
         while (approvedDetail.Quantity > 0 && i < stockInformations.Count)
         {
             var stockInformation = stockInformations[i];
             if (stockInformation.Quantity >= approvedDetail.Quantity)
             {
                 stockInformation.Quantity = stockInformation.Quantity - approvedDetail.Quantity;
                 approvedDetail.Quantity = 0;
             }
             else
             {
                 approvedDetail.Quantity = approvedDetail.Quantity - stockInformation.Quantity;
                 stockInformation.Quantity = 0;
             }
             i++;
         }
     }
 }
开发者ID:USAID-DELIVER-PROJECT,项目名称:ethiopia-hcmis-warehouse,代码行数:35,代码来源:PreferenceCalculator.cs

示例12: Add

        public ActionResult Add(Gallery gallery, ICollection<SelectListItem> categories)
        {
            if (ModelState.IsValid)
            {
                //int[] selectedCategoryIDs = CheckBoxListExtension.GetSelectedValues<int>("CategoriesSelected");
                //if (selectedCategoryIDs.Count<int>() > 0)
                //{
                //    List<Category> selectedCategories = unitOfWork.CategoryRepository.Get(x => selectedCategoryIDs.Contains<int>(x.CategoryID)).ToList<Category>();
                //    gallery.Categories = selectedCategories;
                //}
                int[] selectedCategoryIDs = categories.Where<SelectListItem>(x => x.Selected).Select<SelectListItem, int>(x => Convert.ToInt32(x.Value)).ToArray<int>();
                List<Category> categoriesToAdd = unitOfWork.CategoryRepository.Get(x => selectedCategoryIDs.Contains<int>(x.CategoryID)).ToList<Category>();
                gallery.Categories.Clear();
                foreach (var categoty  in categoriesToAdd)
                {
                    gallery.Categories.Add(categoty);
                }

                unitOfWork.GalleryRepository.Insert(gallery);
                unitOfWork.Save();
                return RedirectToAction("Index");
            }

            ViewBag.MediaManagerCategory = mediaManagerCategory.GetSelectListOfCategories();
            return View(gallery);
        }
开发者ID:joelmccune,项目名称:MediaManagerv2,代码行数:26,代码来源:GalleryController.cs

示例13: BuildElement

        private void BuildElement(ElementBlock elementBlock, ICollection<string> path)
        {
            if (!elementBlock.IsRoot())
            {
                path.Add(elementBlock.Selector.ToCss());
                path.Add(elementBlock.Name);

                //Only add an element to the document when we have reached the end of the path
                if (elementBlock.Properties.Count != 0)
                {
                    var cssProperties = new List<CssProperty>();

                    foreach (var property in elementBlock.Properties)
                        cssProperties.Add(new CssProperty(property.Key, property.Evaluate().ToCss()));

                    //Get path content i.e. "p > a:Hover"
                    var pathContent = path.Where(p => !string.IsNullOrEmpty(p)).JoinStrings(string.Empty);
                    pathContent = pathContent.StartsWith(" ") ? pathContent.Substring(1) : pathContent;
                    document.Elements.Add(new CssElement(pathContent, cssProperties));
                }
            }
            if (elementBlock.Inserts.Count == 0) return;
            foreach (var insert in elementBlock.Inserts)
                document.Elements.Add(new CssElement { InsertContent = insert.ToString() });
        }
开发者ID:JasonCline,项目名称:dotless,代码行数:25,代码来源:LessToCssDomConverter.cs

示例14: SecureByteArrayEquals

        //TODO Perhaps make this more secure
        /// <summary>
        /// Found here: http://stackoverflow.com/questions/16953231/cryptography-net-avoiding-timing-attack
        /// May Need to Fix at some point.
        /// </summary>
        /// <param name="a">The first byte array.</param>
        /// <param name="b">The second byte array.</param>
        /// <returns>True if both byte arrays are equal.</returns>
        public bool SecureByteArrayEquals(ICollection<byte> a, IList<byte> b)
        {
            if (a.Count != b.Count)
                return false;

            return !a.Where((t, i) => t != b[i]).Any();
        }
开发者ID:TRex22,项目名称:StudentSupportSystemGroup10,代码行数:15,代码来源:StringHandler.cs

示例15: Run

        public static ICollection<Hand> Run(ICollection<Hand> hands, ICollection<Card> boardCards)
        {
            _hands = new List<Hand>();
            foreach (var hand in hands)
            {
                _hands.Add(hand);
            }
            var unfoldedHands = _hands.Where(hand => hand.Fold == false).ToList();
            var percentages = GetFoldRaisePercentages(unfoldedHands.Count());
            var raisedHands = unfoldedHands.Where(hand => hand.WinningProbability >= percentages[1]).ToList();

            if (raisedHands.Count > 0)
            {
                PrintRaisedHands(raisedHands);
                foreach (var hand in unfoldedHands.Where(hand => !raisedHands.Contains(hand)))
                {
                    if (hand.WinningProbability < percentages[1])
                    {
                        hand.Fold = true;
                    }
                }
                PrintFoldedHands(unfoldedHands.Where(hand => hand.Fold).ToList());
                Console.WriteLine();
            }

            return _hands;
        }
开发者ID:cheng93,项目名称:TexasHoldem,代码行数:27,代码来源:AiLogic.cs


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