static foreach
Learn about the static foreach loop and how it is a more powerful compile-time feature than foreach.
We'll cover the following...
We'll cover the following...
You saw compile-time foreach earlier in the tuples chapter. Compile-time foreach iterates the loop at compile-time and unrolls each iteration as separate pieces of code. For example, consider the following foreach loop over a tuple:
The compiler unrolls the loop similar to the following equivalent code:
Although very powerful, some properties of compile-time foreach may not be suitable in some cases:
-
With compile-time
foreach, each unrolling of the loop introduces a scope. As seen with theiand member variables above, ...