by Andreas

Conditional breakpoints in Visual Studio

A Visual Studio feature worth checking out is the conditional breakpoint. In short, it allows you to set specific conditions that have to be met for a breakpoint to freeze execution. You have the choice between several types of conditions, like the value of a variable or the number of iterations over a specific breakpoint required before execution stops.

In the following example a list of car manufacturers is enumerated. I want the breakpoint to kick in when and only when the current car is “Subaru”. To achieve this, create a breakpoint like normal (F9) and right click the red marker in the left margin of the editor:

image

Select “Condition” which will open up the following dialog box:

image

Set your condition (standard boolean syntax, in my case car.Equals(“Subaru”) ) and when running the code the breakpoint will ignore all items where this condition if false.

This feature has several other varieties, and it saves you the manual job of iterating through 27 items before the one record that you want to follow through the next code block appears..