Tuesday, June 22, 2010

A great post that stands over the subtleties regards these two iteration possibilities here.

At the end of the day it seems that if you want to store objects of structs (primitive types such int, long etc…), in a generic List, you should use normal foreach (or for) instead if you want to avoid problems. Also removing items in the ForEach method is a thing which should be avoided also when it is possible. Otherwise i promise, the time will come when someone copies you code uses the ForEach to add items instead of removing it!

C#