Is there any way to see every value of the variable as it changes in the watch window? [duplicate]

StackOverflow https://stackoverflow.com/questions/22341900

  •  13-06-2023
  •  | 
  •  

Question

I basically just want to see a history of the variable as it changes during each Continue.

Can it be done? Or should I just log it to a file?

Thanks!

Was it helpful?

Solution

Is your variable a property? If so you can write out to the immediate window in the set

Say you have a class such as

class MyClass
{
    private int myVariable;

    public int MyVariable
    {
        get
        {
            return this.myVariable;
        }
        set
        {
            System.Diagnostics.Debug.Print(value.ToString());
            this.myVariable = value;
        }
    }
}

Then you could call code like this

    MyClass mc = new MyClass();
    mc.MyVariable = 1;
    mc.MyVariable = 2;

And the output would be

1
2

The default setting in Visual Studio is for Debug.Print() to write to the Output Window. If you want it to go to the Immediate Window instead go

Tools > Options > Debugging > General > Redirect all Output Window text to Immediate Window

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top