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


C# ICollection.First方法代码示例

本文整理汇总了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;
        }
开发者ID:v-zubritsky,项目名称:MilitaryFaculty,代码行数:26,代码来源:ReportRow.cs

示例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());
     }
 }
开发者ID:yrox,项目名称:Summer_school,代码行数:12,代码来源:Sentence.cs

示例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();
 }
开发者ID:m-wilczynski,项目名称:Graphinder,代码行数:20,代码来源:RouletteStrategy.cs

示例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");
        }
开发者ID:etkirsch,项目名称:The-DM-Screen,代码行数:29,代码来源:FeedEntryController.cs

示例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));
        }
开发者ID:ivankustera,项目名称:AtomiaStore,代码行数:7,代码来源:FakeCategoryProductsProvider.cs

示例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);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:7,代码来源:DSPExpandProvider.cs

示例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";
         }
     }
 }
开发者ID:snoopie72,项目名称:NrImporter,代码行数:34,代码来源:Form2.cs

示例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);
        }
开发者ID:poskadesign,项目名称:CS-S7-Compiler-Theory,代码行数:26,代码来源:PolishNotation.cs

示例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;
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:21,代码来源:ModelTools.cs

示例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;
 }
开发者ID:MattPuzey,项目名称:Katas,代码行数:8,代码来源:PokerHands.cs

示例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);
        }
开发者ID:TommyNewbie,项目名称:TimeManager,代码行数:8,代码来源:DeleteEventTest.cs

示例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;
        }
开发者ID:naqvitalha,项目名称:CSharpAnalytics,代码行数:13,代码来源:MeasurementUriBuilder.cs

示例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());
        }
开发者ID:CruelMoney,项目名称:AutoSys,代码行数:9,代码来源:RuleCheckers.cs

示例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;
        }
开发者ID:rjonker1,项目名称:lightstone-data-platform,代码行数:10,代码来源:FakeEntryPoint.cs

示例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);
        }
开发者ID:uheerme,项目名称:core,代码行数:54,代码来源:ChannelsControllerTest.cs


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