Performance of foreach vs. List.ForEach(diditwith.net)

submitted by cls2degcls2deg(1535) 5 years, 4 months ago

Today I was iterating a List<int> using a foreach-loop and feeling a bit smug in knowing how much more performance-conscious I was being than if I'd tried doing the same thing with an ArrayList filled with ints. Thanks to the wonder of generics, the C# compiler neatly avoids numerous boxing operations by using a System.Collections.Generic.IEnumerator<int> instance instead of the older System.Collections.IEnumerator. Then I got to thinking: "is this really the fastest way?" Upon investigation, it turns that, no, it isn't the fastest way.

1 comment |category: |Views: 360

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by r.owliaeir.owliaei(30) 2 years, 11 months ago 0

Yeah, i did something like that. you can see it's results here:
http://elemenex.com/index.php?option=com_content&view=article&id=25:foreach-vs-foreach-performance&catid=7:c&Itemid=8
In this article the point was not boxing and unboxing but what was important to me was .ForEach extension method structure.
i will be very glad if i see your comments on my test.;)

Reply

information Login or create an account to comment on this story