I often use the Watch Window in Visual Studio for debugging. But it requires you put all of your code into a single statement (without a semi-colon) to get the result. Is there a way I can use existing variables (that are in scope) and write a code block (multiple lines of code) and test it inline while I’m debugging?
Answer until Microsoft makes an enhancement:
No, this is not possible I guess–having multiple lines (code block) run during debugging.
Yes, you can use Immediate Window for such purposes.
So, for instance when the program execution is stopped on a break point and you want to see state of a variable in the current execution scope or even evaluate deffered LINQ query. Just type in variable name and press ENTER – variable’s value will be printed out. To evaluate LINQ query I’m using
ToList()and then indexer to acces any particular item, for instance you’ve such a query:Now just dorp this in Immediate Window:
Important: you can evaluate only single line of code at the time.
More advanced usage: Immediate Window Commands