1

Is it possible to alter a variable while debugging?

Say for example I have this code:

    string x = "foo"; //would actually be a passed-in variable in the real world.

    var y = "X equals " + x;    

    ==>[BREAKPOINT] return x; 

Is there a way to manually enter or otherwise change the value of "x" when I hit the break point? Also , is it possible to "step back" in the code in the same way that you can press F11 and step through it?

1 Answer 1

3

Yes, there are 2 ways to change a variable:

  • Use the Immediate window. Simply typing x = "a new value" will change it. Also, if you want to check the value of x use ?x
  • You can hover over the variable, and when the value displays in the quickwatch pop-up thing, just click on it an manually change it. (You can also add the variable to watch, or select quickwatch to change it).

If you would like to step to a different instruction, there are 2 ways to do that too:

  • You can right-click on the line you want to go to and select 'Set next statement'. This even works if you have hit an exception while debugging
  • You can drag the yellow arrow that indicates the current instruction to wherever you need it
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.