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.
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.
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.
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.
if (MyStringVariable == "LKOH") Debugger.Break();
you'll need System.Diagnostics namespace
http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With