Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.

The compiler can assume nothing.



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: