When debugging my C#, I often want to know when a variable's value changes and then investigate the state of the program.
Currently, I do it like this:
However, the number of F10s required is annoying.
Surely this has been automated, I thought. But I cannot find this feature in my Microsoft Visual C# Express, which surprises me. After all, the Watch-list does automatically highlight changed values in bright red.
Am I missing something?
You can change a variable in the Evaluate dialog or in the Watch List panel. The Evaluate dialog: To invoke the dialog, press the Call the Evaluate Dialog button on the Debug toolbar, or press the Ctrl+F12 shortcut (this is the default shortcut. You can change it any time.
Press F5 and hover over the type variable again. Repeat this step until you see a value of I in the type variable. Now, press F11 (Debug > Step Into or the Step Into button in the Debug Toolbar). F11 advances the debugger (and executes code) one statement at a time.
When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.
Simple trick for Express edition:
private string myValue; public string MyValue { set { if (this.myValue != value) Debugger.Break(); this.myValue = value; } }
Conditional breakpoints are what you're after, but it appears they are not available in Visual Studio Express.
In Visual Studio (non-Express), the way it works is that you create a conditional breakpoint with an expression equal to your watch value and "Has changed" as your breakpoint condition.
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