When stepping through C# code, I notice that the debugger stops three times in a foreach
declaration:
- First, it highlights the collection.
- Then, it highlights the in operator.
- Last it highlights the variable.
I'd like to understand what the debugger is doing. For example, it makes sense in a for
loop. During initialization, it assigns the variable, then checks the condition. At the beginning of each subsequent loop, it updates the variable, then checks the condition.
It seems in a foreach
, it would need to get an enumerator at the in operator during initialization, then only assign the next item at the beginning of each loop.
I'm using Visual Studio.