2.1.19 Temporarily Changing Values While Debugging

Overview

While paused in Visual Studio, you can temporarily edit an eligible variable value to explore another path. This changes the state of the current debug run, not the source code. Record the original value first so your observation has context.

int portions = 0;
while (portions < 3)
{
    portions++;
}
Test a Different Branch Temporarily
Test a Different Branch Temporarily. While paused in Visual Studio, you can temporarily edit an eligible variable value to explore another path.
Test a Different Branch Temporarily
  • New
  • Changed
  • Removed

Pause before the while condition. If you change portions from 0 to 3 in Locals or Watch, the next condition check is false and the loop body is skipped. If you change it to 2, the body runs once before the next false check. Editing at a later line may not re-evaluate a condition already tested.

Treat the modified value as an experiment. It can quickly show what the program would do if a condition were true or false, but it does not prove that the real application can reach that state. After exploring, restart the run and test with a normal input. This separates a useful debugger experiment from an actual fix.

Trace the Outcome

Repeat the test from a fresh run after changing your source or input normally. A debug-time edit is useful for exploration, but it is not a permanent repair and may differ from a path that the real program can reach.