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


C# ICollection.LastOrDefault方法代码示例

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


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

示例1: CancelCardReservationsExceedingMaxConcurrentTickets

 public static void CancelCardReservationsExceedingMaxConcurrentTickets(ICollection<ICardTuneReservationTicket> tickets, ICollection<CardDetail> freeCards, IDictionary<int, ITvCardHandler> cards)
 {
   if (freeCards != null && freeCards.Count > 2)
   {                        
     Log.Debug("CancelCardReservationsExceedingMaxConcurrentTickets: removing exceeding nr of tickets, only 2 allowed at a time but found {0}", tickets.Count);       
     while (freeCards.Count > 2)
     {
       CardDetail cardDetailForReservation = freeCards.LastOrDefault(); 
       if (cardDetailForReservation != null)
       {
         int idcard = cardDetailForReservation.Card.IdCard;
         CancelCardReservationAndRemoveTicket(cards[idcard], tickets);
         freeCards.Remove(cardDetailForReservation);
       }
     }
   }      
 }
开发者ID:sanyaade-embedded-systems,项目名称:MediaPortal-1,代码行数:17,代码来源:CardReservationHelper.cs

示例2: ChooseCardWhenPlayingSecond

        private PlayerAction ChooseCardWhenPlayingSecond(PlayerTurnContext context, ICollection<Card> orderedCardsByPower)
        {
            ICollection<Card> trumpCards = orderedCardsByPower
                                                .Where(x => x.Suit == context.TrumpCard.Suit)
                                                .ToArray();
                                                
            // If we have a bigger card of the same suit, we play it.
            var biggerCardOfSameSuit = orderedCardsByPower
                    .Where(x => x.Suit == context.FirstPlayedCard.Suit && x.GetValue() > context.FirstPlayedCard.GetValue())
                    .FirstOrDefault();

            // If we have a card of the same suit, we play it.
            if (biggerCardOfSameSuit != null)
            {
                return this.PlayCard(biggerCardOfSameSuit);
            }
            // If we don't have a card of the same suit, we play the smallest trump card
            else
            {
                // We will use trump cards only on strong opponent cards
                if (context.FirstPlayedCard.Type == CardType.Ten || context.FirstPlayedCard.Type == CardType.Ace)
                {
                    if (trumpCards.Count > 0)
                    {
                        return this.PlayCard(trumpCards.LastOrDefault());
                    }
                    else
                    {
                        return this.PlayCard(orderedCardsByPower.LastOrDefault());
                    }
                }

                return this.PlayCard(orderedCardsByPower.LastOrDefault());
            }
        }
开发者ID:tovaneedsa,项目名称:Dr.-Radeva-mrazi-voda,代码行数:35,代码来源:ConsoleWebPlayer.cs

示例3: CancelCardReservationsBasedOnMaxCardsLimit

 public static void CancelCardReservationsBasedOnMaxCardsLimit(ICollection<ICardTuneReservationTicket> tickets, ICollection<CardDetail> freeCards, int maxCards, IDictionary<int, ITvCardHandler> cards)
 {
   int exceedingCardsCount = freeCards.Count() - maxCards;
   if (exceedingCardsCount > 0)
   {
     if (tickets != null && tickets.Count > 0)
     {
       while (freeCards.Count() > exceedingCardsCount)
       {
         CardDetail cardDetailForReservation = freeCards.LastOrDefault();
         if (cardDetailForReservation != null)
         {
           int idcard = cardDetailForReservation.Card.IdCard;
           CancelCardReservationAndRemoveTicket(cards[idcard], tickets);
           freeCards.Remove(cardDetailForReservation);
         }
       }
     }
   }
 }
开发者ID:sanyaade-embedded-systems,项目名称:MediaPortal-1,代码行数:20,代码来源:CardReservationHelper.cs

示例4: ModifySelection

        private void ModifySelection(ICollection<object> itemsToSelect, ICollection<object> itemsToUnselect)
        {
            //clean up any duplicate or unnecessery input
            // check for itemsToUnselect also in itemsToSelect
            foreach (var item in itemsToSelect)
            {
                itemsToUnselect.Remove(item);
            }

            // check for itemsToSelect already in SelectedItems
            foreach (var item in SelectedItems)
            {
                itemsToSelect.Remove(item);
            }

            // check for itemsToUnSelect not in SelectedItems
            foreach (var item in itemsToUnselect.Where(x => !SelectedItems.Contains(x)).ToList())
            {
                itemsToUnselect.Remove(item);
            }

            //check if there's anything to do.
            if (itemsToSelect.Count == 0 && itemsToUnselect.Count == 0)
                return;

            allowedSelectionChanges = true;
            // Unselect and then select items
            foreach (var itemToUnSelect in itemsToUnselect)
            {
                SelectedItems.Remove(itemToUnSelect);
            }

            ((NonGenericObservableListWrapper<object>)SelectedItems).AddRange(itemsToSelect);
            allowedSelectionChanges = false;

            if (itemsToUnselect.Contains(lastShiftRoot))
                lastShiftRoot = null;

            if (!(SelectedItems.Contains(lastShiftRoot) && IsShiftKeyDown))
                lastShiftRoot = itemsToSelect.LastOrDefault();
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:41,代码来源:TreeView.cs


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