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.

cswhatsnew

  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.

CS What's New 2   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.

CS What's New 3   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.

  JoeMayoThis post is an excerpt from the online courseware for our C# 2012: Language Changes and Updates course written by expert Joe Mayo.



Joe Mayo

Joe Mayo is an author, independent consultant, and instructor specializing in Microsoft .NET and Windows 8 technology. He has several years of software development experience and has worked with .NET since July 2000. Joe has written books and contributes to magazines such as CODE Magazine. He has been an active contributor to the .NET community for years, operating the C# Station Web site, authoring the LINQ to Twitter open source project, and speaking regularly at user groups and code camps. For his community contributions, Microsoft has honored Joe with several Most Valuable Professional (MVP) Awards through the years.


C#

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