Foreach on an Array
We reveal that the C# compiler silently rewrites foreach on a one-dimensional array into an equivalent for loop, so there is no performance difference between the two constructs for arrays. The lesson explains that this optimization only applies to 1D arrays; foreach on a List still generates a full enumerator. We use the compiled intermediate language code to prove both cases.
Previous Module
Basic Performance Optimizations
This Module
Array Performance Optimizations