本文整理汇总了C#中ICollection.Count方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Count方法的具体用法?C# ICollection.Count怎么用?C# ICollection.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public JsonResult Add(int encounterId, ICollection<int> newTurnOrder, string description)
{
// This is because the LINQ can't translate this command, it needs a flat int.
var actorId = newTurnOrder.First();
var encounter = context.Encounters.First(e => e.Id.Equals(encounterId));
var actingCharacter = context.Characters.First(p => p.Id.Equals(actorId));
var feedEntry = new EncounterFeedEntry
{
ActingCharacter = actingCharacter,
Description = description
};
context.Actions.Add(feedEntry);
encounter.Initiatives.First(p => p.Character.Id.Equals(newTurnOrder.ElementAt(0)))
.TurnOrder = newTurnOrder.Count()-1;
for(var i=1; i<newTurnOrder.Count(); ++i)
{
encounter.Initiatives.First(p => p.Character.Id.Equals(newTurnOrder.ElementAt(i)))
.TurnOrder = i-1;
}
encounter.FeedEntries.Add(feedEntry);
context.SaveChanges();
return Json("Successfully posted");
}
示例2: recommend
public ICollection<Film> recommend(ICollection<Film> precondition, ICollection<Film> yetRecommended, int Number)
{
if(precondition==null|| precondition.Count<1)
return new List<Film>();
var retList = new List<Film>();
for (int i = 0; i < (Number>0?Number:10); i++)
{
var tmp_film = precondition.ElementAt(new Random().Next(0, precondition.Count()-1));
if(tmp_film.actors!=null&&tmp_film.actors.Count()>0)
{
var tmp_actor = tmp_film.actors.ElementAt(new Random().Next(0, tmp_film.actors.Count()-1));
if (tmp_actor != null)
{
tmp_actor = actorsservice.getActorWithFilmsFromDAL(tmp_actor.ID);
if (tmp_actor != null&&tmp_actor.films.Count()>0)
{
var rec_film = tmp_actor.films.ElementAt(new Random().Next(0, tmp_actor.films.Count() - 1));
if (!yetRecommended.Contains(rec_film) && !retList.Contains(rec_film))
retList.Add(rec_film);
}
}
}
}
return retList;
}
示例3: PointAndSuitCountParameter
private float PointAndSuitCountParameter(Card card, PlayerTurnContext context, ICollection<Card> allowedCards)
{
var cardSuit = card.Suit;
float cardValue = card.GetValue();
float coutOfSuitInHand = allowedCards.Count(x => x.Suit == cardSuit);
return (11f - cardValue) * coutOfSuitInHand;
}
示例4: RedisLock
public RedisLock(
ICollection<ConnectionMultiplexer> redisCaches,
string resource,
TimeSpan expiryTime,
TimeSpan? waitTime = null,
TimeSpan? retryTime = null,
Func<string, string> redisKeyFormatter = null,
IRedLockLogger logger = null)
{
this.redisCaches = redisCaches;
var formatter = redisKeyFormatter ?? DefaultRedisKeyFormatter;
this.logger = logger ?? new NullLogger();
quorum = redisCaches.Count() / 2 + 1;
quorumRetryCount = 3;
quorumRetryDelayMs = 400;
clockDriftFactor = 0.01;
redisKey = formatter(resource);
Resource = resource;
LockId = Guid.NewGuid().ToString();
this.expiryTime = expiryTime;
this.waitTime = waitTime;
this.retryTime = retryTime;
Start();
}
示例5: Insert
public static int Insert(this Collection<Instruction> collection, int index, ICollection<Instruction> instructions)
{
foreach (var instruction in instructions.Reverse())
{
collection.Insert(index, instruction);
}
return index + instructions.Count();
}
示例6: IsRuleMet
public bool IsRuleMet(ICollection<string> data, ICollection<string> criteriaData)
{
if (data.Count() != 1 && criteriaData.Count() != 1)
{
return !criteriaData.Except(data).Any();
}
return data.First().Contains(criteriaData.First());
}
示例7: CheckPageExercises
private static void CheckPageExercises(ExercisePage page, ICollection<Exercise> expectedExercises)
{
foreach (var expectedExercise in expectedExercises)
{
Assert.That(page.IsShowing(expectedExercise), string.Format("exercise {0} was not on page", expectedExercise.Name));
}
Assert.That(page.ExerciseCount, Is.EqualTo(expectedExercises.Count()));
}
示例8: HasBookToReturn
private async Task HasBookToReturn(ICollection<Loan> books)
{
if (books.Count() == 0)
{
Console.WriteLine(Display.NotBooksToReturn);
return;
}
await ShowNotReturningBook(books);
}
示例9: SetCheckState
private void SetCheckState(int visgroupId, ICollection<MapObject> visItems)
{
var numHidden = visItems.Count(x => x.IsVisgroupHidden);
CheckState state;
if (numHidden == visItems.Count) state = CheckState.Unchecked; // All hidden
else if (numHidden > 0) state = CheckState.Indeterminate; // Some hidden
else state = CheckState.Checked; // None hidden
VisgroupPanel.SetCheckState(visgroupId, state);
}
示例10: AddRandomPaths
private void AddRandomPaths(ICollection<Location> locations)
{
var rnd = new Random();
locations.ForEach(location =>
{
for (int i = 0; i < rnd.Next(0, 3); i++)
{
location.ConnectedLocations.Add(locations.ElementAt(rnd.Next(0, locations.Count())));
}
});
}
示例11: WriteAssemblyAttributesInternal
public virtual void WriteAssemblyAttributesInternal(AssemblyDefinition assembly, ICollection<string> assemblyNamespaceUsings,
ICollection<string> mainModuleNamespaceUsings, bool writeUsings = false, ICollection<string> attributesToIgnore = null)
{
if (writeUsings && (assemblyNamespaceUsings.Count() > 0 || mainModuleNamespaceUsings.Count() > 0))
{
Writer.WriteAssemblyUsings();
Writer.WriteLine();
Writer.WriteLine();
}
AttributeWriter.WriteAssemblyAttributes(assembly, attributesToIgnore);
}
示例12: GetBestSynonym
public static WordModel GetBestSynonym(WordModel word, ICollection<WordModel> synonyms, WordTrait desired = null)
{
if (!synonyms.Any())
{
return word;
}
if (synonyms.Count() == 1)
{
return synonyms.First();
}
return BestSynonymMatchByTrait(synonyms, desired);
}
示例13: ValidateStrategy
private void ValidateStrategy(ICollection<IPlayer> players, IBoard board)
{
if (players.Count() != GlobalConstants.StandartGameNumberOfPlayers)
{
throw new InvalidOperationException("Standart Play Game Initialization Strategy needs exactly two players!");
}
if (board.TotalRows != GlobalConstants.StandartGameTotalBoardRows ||
board.TotalCols != GlobalConstants.StandartGameTotalBoardCols)
{
throw new InvalidOperationException("Standart Play Game Initialization Strategy needs 8x8 board!");
}
}
开发者ID:King-Survival-3,项目名称:HQC-Teamwork-2015,代码行数:13,代码来源:StandartStartGameInitializationStrategy.cs
示例14: AppendToStore
public void AppendToStore(string name, ICollection<MessageAttribute> attribs, long streamVersion, ICollection<object> messages)
{
using (var mem = new MemoryStream())
{
_serializer.WriteAttributes(attribs, mem);
_serializer.WriteCompactInt(messages.Count(), mem);
foreach (var message in messages)
{
_serializer.WriteMessage(message, message.GetType(), mem);
}
_appendOnlyStore.Append(name, mem.ToArray(), streamVersion);
}
}
示例15: ServerBatchRefresher
public ServerBatchRefresher(string inProgressText, ICollection<Server> items, ICollection<Server> _oldItems = null)
{
_items = items;
_removedItems = new List<Server>();
if (_oldItems != null)
{
foreach (Server item in _oldItems)
{
if (_items.Count(x => x.Id.Equals(item.Id)) < 1) //this server has been removed
_removedItems.Add(item);
}
}
InProgressText = inProgressText;
}