Consider 2 scripts of code:
Statement 1:
foreach( object A in collection)
{
int value = A.value;
A.value = 10;// Compiler error, since we cannot modify it.
}
Statement 2:
for(int i = 0; i < collection.Count; i++)
{
object A = collection[i];
A.value = 10;// Valid statement
}
In many cases, Statement 1 is the best choice.