Blog
C# 2012: Debugging Tips
Excerpt by Joe Mayo | August 22, 2013
For effective debugging, you need to be able to set a breakpoint. The easiest way to set a breakpoint is to click your mouse in the gutter, which is the vertical space to the left of the editor window, shown in the Figure below.
The Figure above. Click in the gutter to create a breakpoint. After setting a breakpoint, you can start debugging by selecting DEBUG|Start Debugging or by pressing the F5 key. This will run the program until it reaches the breakpoint and then stop. You can customize an individual breakpoint with conditions. Right-click on the red dot in the gutter and you'll see options for Conditions, Hit Count, and more. You can use Hit Count to stop on the breakpoint after it executes a specified number of times, such as in a loop. Condition, shown in the Figure below, lets you define an expression that will make the code hit a breakpoint on that line when the expression is true.
The Figure above. You can set conditions on a breakpoint. After setting a number of breakpoints, you'll want to organize and keep track of them. You can open the Breakpoints window where you manage breakpoints, shown in the Figure above, by selecting DEBUG|Windows|Breakpoints.
The Figure above. The Breakpoints window lets you manage breakpoints. From the Breakpoints window, you can create new breakpoints, specify columns to view, and filter the list with Search. You can organize the breakpoints by right-clicking on a breakpoint and selecting Edit labels. Then you can search on labels and perform actions on the entire group of breakpoints as a whole. When the program stops, you can inspect its state by hovering over variables with a mouse or viewing debugger windows.
This post is an excerpt from the online courseware for our C# 2012: Language Changes and Updates course written by expert Joe Mayo.
Joe Mayo
This course excerpt was originally posted August 22, 2013 from the online courseware C# 2012, Part 4 of 4: Language Changes and Updates by Joe Mayo