I have a sequence of items represented by IEnumerable
I need to loop thru these items, and It should be a for-loop because the index is important.
My question is, is there a difference in performance between the following 2 options?
1.
for (int i = 0; i < items.Count(); i++)
{
//Do something
}
var itemsLength = items.Count();
for (int i = 0; i < itemsLength; i++)
{
//Do something
}
In other words, does the method items.Count() run again and again on each iteration in option 1?