for loop, foreach loop, list.foreach… interesting

I was evaluating the use of List.ForEach() in C# and ran across this interesting post that evaluates the speed of each. What is interesting is that the List.ForEach() is faster even than a for loop 🙂 And it’s not really even close which is mind boggling.

I’m a huge fan of List, so this will be standard mode of operation.
Meanwhile, I was looking for a way to sum the value of one field in a List.


I have a list of ‘Widgets’, each Widget has a Price. I want to get a total price of the widgets in my list.

Here is an example of something I was working on:

bomberList is a List
aircraftList is a List

bomberList.ForEach(delegate(string s)
Aircraft ac = aircraftList.Find(delegate(Aircraft a)
return a.ACName == s;
if(ac != null)
ac.IsBomber = true;

I need to set the IsBomber to true for every aircraft that name is matched of bomberList


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s