本文整理汇总了C#中ICollection.First方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.First方法的具体用法?C# ICollection.First怎么用?C# ICollection.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.First方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Unify
public static ReportRow Unify(ICollection<ReportRow> reportRows)
{
if (reportRows == null || reportRows.Count == 0)
{
throw new ArgumentException("reportRows");
}
var newRow = new ReportRow
{
Name = reportRows.First().Name,
MaxValue = reportRows.First().MaxValue,
Results = new List<int>()
};
for (var i = 0; i < reportRows.Count; i++)
{
if (newRow.Name != reportRows.ElementAt(i).Name)
{
throw new Exception("Rows discrepancy");
}
newRow.Results.AddRange(reportRows.ElementAt(i).Results);
}
return newRow;
}
示例2: RemoveConsonentWord
public void RemoveConsonentWord(int length)
{
var itemsToRemove = GetWordsOfLength(length)
.Where
(word =>
((word as Word).IsConsonent == true));
SentenceItems = SentenceItems.Except(itemsToRemove).ToList();
if (SentenceItems.First().GetType() == typeof(Punctuation))
{
SentenceItems.Remove(SentenceItems.First());
}
}
示例3: Set
/// <summary>
/// Resets strategy with new population of individuals.
/// </summary>
/// <param name="newPopulation">New population for strategy.</param>
public void Set(ICollection<Individual> newPopulation)
{
if (newPopulation == null)
throw new ArgumentException(nameof(newPopulation));
if (newPopulation.Count == 0)
throw new InvalidOperationException("Attempt to set empty population");
var problem = newPopulation.First().Problem;
var graph = newPopulation.First().Graph;
if (newPopulation.Any(i => i.Graph != graph || i.Problem != problem))
throw new AlgorithmException("Setting up new population", "Individuals in population represent either different graphs or different problems");
_population = newPopulation;
//In case is not SortedSet<T>
if (!(_population is SortedSet<Individual>))
_population = _population.OrderBy(p => p.SolutionFitness).ToList();
InitializeRoulette();
}
示例4: 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");
}
示例5: GetProducts
public IEnumerable<Product> GetProducts(ICollection<SearchTerm> terms)
{
var allProducts = GetAllProducts();
var category = terms.First().Value;
return allProducts.Where(p => p.Categories.Select(c => c.Name).Contains(category));
}
示例6: ApplyExpansions
public IEnumerable ApplyExpansions(IQueryable queryable, ICollection<ExpandSegmentCollection> expandPaths)
{
Debug.Assert(expandPaths.Count == 1, "multiple expand paths not supported");
Debug.Assert(expandPaths.First().Count == 1, "Deep or empty expands not supported segment collection");
return new DSPExpandEnumerable(queryable);
}
示例7: Form2
public Form2(ICollection<UserEventInfo> deltakere, EventResultHandler handler)
{
_eventResultHandler = handler;
InitializeComponent();
this._deltakere = deltakere;
var bindingList = new BindingList<UserEventInfo>(deltakere.ToList());
var source = new BindingSource(bindingList,null);
dataGridView1.DataSource = source;
dataGridView1.ReadOnly = false;
if (deltakere.First() != null)
{
//var x = new MockedEventService();
//textBox1.Text = x.GetEvents("adsf", 2016).ToList().FirstOrDefault().Id1.ToString();
//List<Event> eventer = eventService.GetEvents("adsf", DateTime.Now.Year).ToList();
var eventer = _eventResultHandler.GetEvents(new DateTime(2015, 5, 10), new DateTime(2015, 10, 31)); //DateTime.Now
if (eventer.Count > 0)
{
label2.Text = $"ID={eventer.First().Id}";
listBox1.Items.Clear();
listBox1.DataSource = eventer;
listBox1.DisplayMember = "DisplayName";
listBox1.ValueMember = "Id";
}
else
{
label2.Text = "Velg event...";
listBox1.Items.Clear();
listBox1.DataSource = eventer;
listBox1.DisplayMember = "DisplayName";
listBox1.ValueMember = "Id";
}
}
}
示例8: InfixToPrefix
public static IRvalueConstruct InfixToPrefix(ICollection<object> construct)
{
if (construct.Count == 1)
return construct.First() as IRvalueConstruct;
var output = new Stack<object>();
var operators = new Stack<object>();
// separate rvalues and operators
foreach (var c in construct) {
if (c is IRvalueConstruct)
output.Push(c);
else if (c is ResolvedToken) {
if (operators.Any() && RL.OperatorPrecedence((c as ResolvedToken).Type) < RL.OperatorPrecedence((operators.Peek() as ResolvedToken).Type)) {
Merge(output, operators);
}
operators.Push(c);
}
}
// merge to prefix notation
Merge(output, operators);
return Dimensionalize(output);
}
示例9: DeleteComponents
/// <summary>
/// Deletes the specified components from their parent containers.
/// If the deleted components are currently selected, they are deselected before they are deleted.
/// </summary>
public static void DeleteComponents(ICollection<DesignItem> items)
{
DesignItem parent = items.First().Parent;
PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Delete);
try {
ISelectionService selectionService = items.First().Services.Selection;
selectionService.SetSelectedComponents(items, SelectionTypes.Remove);
// if the selection is empty after deleting some components, select the parent of the deleted component
if (selectionService.SelectionCount == 0 && !items.Contains(parent)) {
selectionService.SetSelectedComponents(new DesignItem[] { parent });
}
operation.DeleteItemsAndCommit();
} catch {
operation.Abort();
throw;
}
}
示例10: StraightFlushCheck
public static bool StraightFlushCheck(ICollection<Card> cardsinHand)
{
// Are all cards in hand of the same Rank?
var firstCard = cardsinHand.First();
if (cardsinHand.All(s => s.Rank == firstCard.Rank))
return true;
return false;
}
示例11: InitializeController
public EventsController InitializeController(ICollection<Event> events)
{
var repo = new Mock<IEventRepository>();
repo.Setup(n => n.GetAll()).Returns(events.AsEnumerable());
repo.Setup(n => n.Delete(It.IsAny<int>())).Callback<int>(id => events.Remove(events.First(n => n.Id == id)));
return new EventsController(repo.Object);
}
示例12: CarryForwardParameters
/// <summary>
/// Carry forward the cd parameter value to future event & timing activities to know which page they occurred on.
/// </summary>
/// <param name="activity">Current activity being processed.</param>
/// <param name="parameters">Current parameters for this request.</param>
private void CarryForwardParameters(MeasurementActivity activity, ICollection<KeyValuePair<string, string>> parameters)
{
if ((activity is EventActivity || activity is TimedEventActivity) && lastCdParameterValue != null)
parameters.Add(KeyValuePair.Create("cd", lastCdParameterValue));
if (parameters.Any(k => k.Key == "cd"))
lastCdParameterValue = parameters.First(p => p.Key == "cd").Value;
}
示例13: 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());
}
示例14: GetResponsesForCarId
public ICollection<IPointToLaceProvider> GetResponsesForCarId(ICollection<IPointToLaceRequest> request)
{
_buildSourceChain = new FakeSourceChain();
if (_checkForDuplicateRequests.IsRequestDuplicated(request.First())) return null;
_bootstrap = new Initialize(new Collection<IPointToLaceProvider>(), request, _bus, _buildSourceChain);
_bootstrap.Execute(ChainType.CarId);
return _bootstrap.DataProviderResponses;
}
示例15: SetUpClass
public static void SetUpClass(TestContext context)
{
var seq = new SequentialGenerator<int> { Direction = GeneratorDirection.Ascending };
var gen = new RandomGenerator();
data_users = Builder<User>
.CreateListOfSize(10)
.All()
.With(u => u.DisplayName = gen.Phrase(15))
.Build();
data_channels = Builder<Channel>
.CreateListOfSize(20)
.All()
.With(m => m.Id = seq.Generate())
.And(x => x.Name = gen.Phrase(15))
.And(x => x.AuthorId = gen.Phrase(10))
.And(x => x.Author = data_users.First())
.And(x => x.Loops = gen.Boolean())
.And(x => x.DateCreated = gen.DateTime())
.And(x => x.DateUpdated = x.DateCreated + new TimeSpan(3, 0, 0))
.Random(10)
.With(x => x.DateDeactivated = x.DateUpdated + new TimeSpan(3, 0, 0))
.Build();
data_musics = Builder<Music>
.CreateListOfSize(50)
.All()
.With(m => m.Id = seq.Generate())
.And(m => m.LengthInMilliseconds = gen.Int())
.And(m => m.SizeInBytes = gen.Int())
.And(m => m.DateCreated = gen.DateTime())
.And(m => m.DateUpdated = m.DateCreated + new TimeSpan(3, 0, 0))
.Build();
channels = new Mock<ChannelService>(null);
musics = new Mock<MusicService>(null);
channels
.Setup(x => x.All())
.ReturnsAsync(data_channels);
channels
.Setup(x => x.Paginate(0, 10))
.ReturnsAsync(data_channels.Take(10).ToList());
channels
.Setup(x => x.ActiveChannels(0, 4))
.ReturnsAsync(data_channels.Take(4).ToList());
channels
.Setup(c => c.Deactivate(It.IsAny<Channel>()))
.ReturnsAsync(1);
}