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


C# System.Collections.Generic.ForEach方法代码示例

本文整理汇总了C#中System.Collections.Generic.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.ForEach方法的具体用法?C# System.Collections.Generic.ForEach怎么用?C# System.Collections.Generic.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Generic的用法示例。


在下文中一共展示了System.Collections.Generic.ForEach方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ForEachArray

        public void ForEachArray()
        {
            var arr = new[] { 1, 2, 3, 4 };
            int count = 0;
            arr.ForEach(item => count += item);

            Assert.AreEqual(10, count);
        }
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:8,代码来源:IEnumerableExtensionsTests.cs

示例2: ForEach_WithCollectionOf10_Iterates10Times

        public void ForEach_WithCollectionOf10_Iterates10Times()
        {
            var totalIterations = 0;
            var listOfNumbers = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            listOfNumbers.ForEach(number => totalIterations++);

            Assert.That(totalIterations, Is.EqualTo(10));
        }
开发者ID:martinrue,项目名称:Tinyweb,代码行数:9,代码来源:ExtensionsTests.cs

示例3: ForEach

        public void ForEach()
        {
            int sum = 0;
            IEnumerable<int> numbers = new [] {1, 2, 3, 5, 8};

            numbers.ForEach(n => sum += n);

            Assert.That(sum, Is.EqualTo(19));
        }
开发者ID:peterbucher,项目名称:silkveil,代码行数:9,代码来源:ExtensionMethodsTests.cs

示例4: ForEach_WithCollectionOf1_Iterates1Time

        public void ForEach_WithCollectionOf1_Iterates1Time()
        {
            var totalIterations = 0;
            var listOfNumbers = new[] { 1 };

            listOfNumbers.ForEach(number => totalIterations++);

            Assert.That(totalIterations, Is.EqualTo(1));
        }
开发者ID:martinrue,项目名称:Tinyweb,代码行数:9,代码来源:ExtensionsTests.cs

示例5: ForEach_should_enumerate_the_collection

        public void ForEach_should_enumerate_the_collection()
        {
            int sum = 0;
            var values = new[] { 1, 1, 1 };

            values.ForEach(x => sum += x);

            sum.Should().Be(3);
        }
开发者ID:jasonreimer,项目名称:Praetorium,代码行数:9,代码来源:CollectionExtensionSpecs.cs

示例6: ForEach_with_function_executes_function_over_every_element

        public void ForEach_with_function_executes_function_over_every_element()
        {
            var executeWith = new List<int>();
            var elements = new[] {1, 2, 3, 4};

            elements.ForEach(executeWith.Add);

            Assert.That(executeWith, Is.EquivalentTo(elements));
        }
开发者ID:scaredfinger,项目名称:ActiveWidgets,代码行数:9,代码来源:ForEachExtensionFixture.cs

示例7: WhenForEachExecuted_ThenCallsActionForEach

        public void WhenForEachExecuted_ThenCallsActionForEach()
        {
            var strings = new[] { "foo", "bar" };
            var called = new List<string>();

            strings.ForEach(s => called.Add(s));

            Assert.Equal(strings, called);
        }
开发者ID:netfx,项目名称:extensions,代码行数:9,代码来源:ForEachSpec.cs

示例8: ForEach_WithCollection_IteratesEachItem

        public void ForEach_WithCollection_IteratesEachItem()
        {
            // arrange
            IEnumerable<int> numbers = new[]{5, 4, 3};
            string concatenated = string.Empty;

            // act
            numbers.ForEach(number => concatenated += number);

            // assert
            Assert.AreEqual("543", concatenated);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:12,代码来源:CollectionExtensionsTests.cs

示例9: ForEach_WithIEnumerable_PerformsAction

        public void ForEach_WithIEnumerable_PerformsAction()
        {
            // Arrange
            var values = new[] { "William", "Sarah", "Abigail", "Jessica" };

            //Act
            var result = string.Empty;
            values.ForEach(x => result += x);

            // Assert
            Assert.That(result, Is.EqualTo(string.Join(string.Empty, values)));
        }
开发者ID:wduffy,项目名称:RazorMail,代码行数:12,代码来源:CollectionExtensionsTests.cs

示例10: Should_CallActionForEachItem_WhenForEachIsInvoked

        public void Should_CallActionForEachItem_WhenForEachIsInvoked()
        {
            // arrange
            var items = new[] {1, 2, 3, 4, 5};
            var visitedItems = new List<int>();

            // act
            items.ForEach(visitedItems.Add);

            // assert
            visitedItems.Should().BeEquivalentTo(items);
        }
开发者ID:kekekeks,项目名称:OAuth2,代码行数:12,代码来源:EnumerableExtensionsTests.cs

示例11: SaveOrLoad

 public void SaveOrLoad(Serializer serializer)
 {
     if (serializer.IsLoading)
     {
         Images.Clear();
     }
     var objectEntries = new[]
     {
         LoadAndSaveEntry.Create(reader => reader.ReadUInt32(), writer => writer.WriteUInt32(0), 8),
         LoadAndSaveEntry.Create(reader => reader.ReadUInt32(), writer => writer.WriteUInt32(0), 8),
         LoadAndSaveEntry.Create(reader =>
             {
                 Walk = new Point(reader.ReadInt16(), reader.ReadInt16());
             }, writer =>
             {
                 writer.WriteInt16(Walk.X);
                 writer.WriteInt16(Walk.Y);
             }, 8),
         LoadAndSaveEntry.Create(reader => Number = reader.ReadUInt16(), writer => writer.Write(Number), 8),
         LoadAndSaveEntry.Create(reader =>
             {
                 Position = new Point(reader.ReadInt16(), reader.ReadInt16());
             }, writer =>
             {
                 writer.WriteInt16(Position.X);
                 writer.WriteInt16(Position.Y);
             }, 8),
         LoadAndSaveEntry.Create(reader => Width = reader.ReadUInt16(), writer => writer.WriteUInt16(Width), 8),
         LoadAndSaveEntry.Create(reader => Height = reader.ReadUInt16(), writer => writer.WriteUInt16(Height), 8),
         LoadAndSaveEntry.Create(reader => ActorDir = reader.ReadByte(), writer => writer.WriteByte(ActorDir), 8),
         LoadAndSaveEntry.Create(reader => ParentState = reader.ReadByte(), writer => writer.WriteByte(ParentState), 8),
         LoadAndSaveEntry.Create(reader => Parent = reader.ReadByte(), writer => writer.WriteByte(Parent), 8),
         LoadAndSaveEntry.Create(reader => State = reader.ReadByte(), writer => writer.WriteByte(State), 8),
         LoadAndSaveEntry.Create(reader => reader.ReadByte(), writer => writer.WriteByte(0), 8),
         LoadAndSaveEntry.Create(reader => Flags = (DrawBitmaps)reader.ReadByte(), writer => writer.WriteByte((byte)Flags), 46),
     };
     objectEntries.ForEach(e => e.Execute(serializer));
 }
开发者ID:scemino,项目名称:nscumm,代码行数:38,代码来源:ObjectData.cs


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