Execute custom code while debugging in Visual Studio with the Immediate Window

Software category image

The Immediate Window allows to execute code while debugging. Here is how you do it.

You just hit a debugger breakpoint and want to execute some custom code that is not part of the actual code base? The Immediate Window is your friend ?

Open it with the menu Debugging, then select Windows, and finally choose Immediate Window.

Type your code and press enter, it will be executed immediately.

Video of Immediate Window in Visual Studio by author
Video of Immediate Window in Visual Studio by author

Be aware that you can only use imported namespaces. So if your compiler snapshot doesn’t contain an import for System.Collections.Generic, you can’t use IEnumerable<T>.

Find more Visual Studio related articles here