Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 6: Debugging with Visual Studio 159
Operation Explanation
Step Over Executes the code in the current line and moves to the next line of code where
it again pauses, waiting for your instruction. Perform a Step Over by selecting
Debug | Step Over, pressing
F10, or clicking the Step Over button in the toolbar.
You can also right- click and select this option. Most Visual Studio developers will
have the
F10 shortcut memorized in short order.
Step Into Specific When the current line is on a method call, a Step Into will move control to the first
line of the method being called and execution will pause there. Perfor
m the Step
Into by selecting Debug | Step Into, pressing
F11, or clicking the Step Into button in
the toolbar.
F11 is the fastest way for you to do this operation.
Step Out If you’re in a method, you can move back to the caller by performing a Step Out
operation. Perform a Step Out by selecting Debug | Step Out, pressing
SHIFT-F11, or
clicking the Step Out button on the toolbar. Note that no lines of code are skipped
inside the function; they still run following your program’s logic. Your program will
automatically pause at the line of code following this function’s return.
Run to Cursor Sometimes you want to execute a block of code and stop at a certain line. You
could set another breakpoint and run until you hit the breakpoint. However, a
quicker way when you don’t want to keep a new breakpoint around is to right-click
the line you want to stop at and select Run To Cursor. Again, no lines of code are
skipped; the program will merely pause when it gets to the line you placed your
cursor on. Optionally, you can click the line to run to and press
CTRL-F10. This is
particularly useful if you don’t feel like stepping through every iteration of a loop.
Set Next Statement You can skip forward and backward over multiple lines of code without executing
the skipped code. For example, it’s easy to step over a method, only to realize
that you really wanted to step into that method. You don’t want to restart the
application unless you need to. To get back to that line of code so that you can
step into the method call, select the yellow arrow in the margin and drag it back
up to the method call. Then you can do a Step Into. Alternatively, if you have one
or more statements that you don’t want to execute, drag the yellow arrow in the
margin to the statement following the code you don’t want to run and then use
stepping operations to resume your debugging session. This technique is also
quite handy when you are using the Edit and Continue feature, where you can
change your program on the fly, experiment with different coding ideas you may
have, and rerun those lines of code instantly. Note that VS does not reset variables
back to initial states, so you may have to manually reset values in order to get the
results you expect.
Table 6-2 Step Operations
A Step Over operation executes the code in the current line and moves to the next. You
can perform a Step Over by selecting Debug | Step Over, pressing
F10, or clicking the Step
Over button in the toolbar.
You now know how to step through code, which is useful. However, the ability to see
the values of variables and watch them change is an important skill, which you learn about
in the next section.