本文整理汇总了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);
}
}
}
}
示例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());
}
}
示例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);
}
}
}
}
}
示例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();
}