> with List<T> there's a guarantee that you cannot modify the list while enumerating over it, so could the compiler theoretically assume that when using foreach?
No such guarantee exists.
The only guarantee there is is that enumeration will throw on next iteration after a modification.
No such guarantee exists.
The only guarantee there is is that enumeration will throw on next iteration after a modification.
The compiler can assume nothing.