Skip to content

Question about inconsistent code generation while using "foreach" and "List<T>" #106817

Discussion options

You must be logged in to vote

ListForEach uses List<T>.Enumerator.MoveNext(), which throws InvalidOperationException if the list has been modified after the enumerator was created.

ListFor and ArrayFor don't check that because they use just an integer index rather than a enumerator object.

ArrayForEach doesn't check that because arrays don't keep track of modifications.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@huoyaoyuan
Comment options

@KalleOlaviNiemitalo
Comment options

Answer selected by danmoseley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
untriaged New issue has not been triaged by the area owner needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
4 participants
Converted from issue

This discussion was converted from issue #106816 on August 22, 2024 14:22.