Tip 7.36: You can use the Immediate Window as a glorified calculator or side-debugger within your debugger
“Visual Studio Tips, 251 ways to improve your Productivity in Visual Studio“, courtesy of ‘Sara Ford’
Sara Ford’s Blog
Sara AsideShe found the Immediate Window especially useful when she was doing the math to automate dragging a tool window from a docked location to a docking target. She basically had to do the math to calculate a straight line between the two points in order to send the coordinates to the mouse drag functions. If she did the math incorrectly (and the inside joke here is she has a math degree), she could pull up the Immediate Window and play with the calculations over and over again without interfering with the main debugger. This means that the variables and state of the main debugger would remain the same, unless she purposefully modified a value in the Immediate Window. |
Let’s start off with a very simple example. Let’s say that you have the basic “Hello World” console app, but you want to print out the result of some calculation. Notice how the console app just has “Hello World.”
If she puts a breakpoint at the very end of this simple console app, she can bring up the Immediate Window via Debug–Windows–Immediate and do whatever she needs. Let’s say she needed to use the Immediate Window as a glorified calculator. She can figure out the value of 1 + 1, as shown in this Visual C# console app.
Since we’re in a console application, we can even have the value of i printed to the console window via the Immediate Window.
And now the value of 2 appears in the console window.
Happy Programming! =)