I have seen in different places that we should not use foreach to iterate through SPListItemCollection, but I can't find explanation, why?
E.g. http://de.slideshare.net/ghurlman/sharepoint-development-101/21
Bad:
foreach (SPListItem item in myList.Items)
{
// loop
}
Good:
SPListItemsCollection items = myList.Items;
for (int i = 0; i < items.Count; i++)
{
// loop
}
But the code is really different, we can get items and use it with foreach as well
SPListItemsCollection items = myList.Items;
foreach (SPListItem item in items)
{
// loop
}
Which one should I use and why?