This is lesson 11 of 12 in this module Course 98% complete

Demo: For and Foreach in Intermediate Language

Premium Content

Sign in with your account or join us to access this lesson.

The lesson disassembles the benchmark DLL to confirm that for on a list calls List.GetItem, foreach on a list calls GetEnumerator and MoveNext, and both for and foreach on a 1D array produce identical ldelm-based loop code. We demonstrate exactly why the enumerator path is slower: every iteration requires a virtual method call to advance to the next element.