本文整理汇总了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;
}
示例2: Sort
public IEnumerable<String> Sort(
ICollection<String> strings)
{
return strings
.Where(item => item.Contains(_keyword))
.Concat(strings.Where(item => !item.Contains(_keyword)));
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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++;
}
}
}
示例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);
}
示例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() });
}
示例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();
}
示例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;
}