Setting a Breakpoint
To get started with the debugger, return to Example 8-1 in Chapter 8. You’ll be putting a breakpoint on the first line of Main( )
to see how this code actually works. A breakpoint is an instruction to the debugger to stop running. You set a breakpoint, run the program, and the debugger runs the program up until the breakpoint. Then you have the opportunity to examine the value of your variables at this point in the execution. Examining your program as it runs can help you untangle otherwise impenetrable problems. You’ll often set multiple breakpoints, which allows you to skip through your program, examining the state of your object at selected locations.
You can set a breakpoint in many different ways. The easiest is to click in the left margin of the code window. This causes a red dot to appear in the margin next to the relevant line of code, which is also highlighted in red, as shown in Figure 9-1 (although you can’t see the color in the book). Open Example 8-1 from Chapter 8, if you haven’t already, and click in the gray margin next to the first line of Main( )
(Tester
t
=
new
Tester( )
). Notice that as you hover over the breakpoint, a tool tip tells you the line on which the breakpoint appears.
You are now ready to run the program to the breakpoint. To do so, you must be sure to run in debug mode, which you can do by clicking the Start button () or by choosing ...
Get Learning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.