Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional breakpoint in Visual Studio

I want to set a breakpoint on a certain line in C# code when some other variable is equal to a specific value, say:

MyStringVariable == "LKOH"

How can I do that?

I tried to right click on breakpoint icon -> Condition and then typed MyStringVariable == "LKOH" and Visual Studio said it cannot evaluate it.

like image 745
Captain Comic Avatar asked Feb 19 '10 14:02

Captain Comic


People also ask

How do I add a conditional breakpoint in Visual Studio code?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

What is conditional breakpoint?

Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.

What is conditional breakpoint in C#?

This is the concept of Breakpoint Conditions. As the name itself suggests, it is setting the breakpoints that are hit, only when a certain condition is met. It's easy to implement as well. Create a new application and set a normal breakpoint. So this will be hit every time the Page_Load executes.


1 Answers

if (MyStringVariable == "LKOH") Debugger.Break();

you'll need System.Diagnostics namespace

http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx

like image 143
Danny G Avatar answered Oct 10 '22 06:10

Danny G