fdkgfosfskjdlsjdlkfsf
fdkgfosfskjdlsjdlkfsf

Reputation: 3301

In VS2019, automatically change variable value while debugging?

I have an If statement that looks like this:

if (condition1 == "True" && condition2 == "True" && condition3 == "True" && condition4 == "True")

Instead of having to change every value during debugging, is it possible to automatically change the value of condition1 to condition4 to "True" when the breakpoint's hit?

I just want the debugger to enter the If statement even though the conditions aren't met. It's a pain in the butt to edit every value once the If statement's hit.

Upvotes: 0

Views: 596

Answers (1)

rickvdbosch
rickvdbosch

Reputation: 15621

The simplest solution would most probably be to Change the execution flow while debugging.

With the debugger paused on a line of code, use the mouse to grab the yellow arrow pointer on the left. Move the yellow arrow pointer to a different point in the code execution path. Then you use F5 or a step command to continue running the app.

Move the execution pointer

By changing the execution flow, you can do things like test different code execution paths or rerun code without restarting the debugger.

This enables you to set a breakpoint on the if-statement, and drag execution into the if whenever necessary. This way you don't even have to change variables, but you can simply decide to execute the statement(s) inside the if-statement whenever you want to test them.

Alternatively, look at how you can Observe a single variable or expression with QuickWatch and change the value for the variable(s) there.

The QuickWatch dialog

Upvotes: 2

Related Questions