Home > Software engineering >  is it possible in debugging, to know if two variables are the same object?
is it possible in debugging, to know if two variables are the same object?

Time:09-17

I am using Visual Studio 2019 community and I have this code:

if(this != myOtherObject
   && anotherVariable != true)
{
     //do something
}

Here the idea is that I have various conditions in the if. So i would like to know if there is some way in debugging to know if it is the first condition true or the second and so on.

If not, the only way that I think it is possible is in this way:

if(this != myOtherObject)
{
    if(anotherVariable != true)
    {
        //do something
    }
}

thanks.

CodePudding user response:

  • Put a breakpoint in your condition.

  • Start Debugging (F5)

  • Highlight this != myOtherObject in your condition

  • Right-click and select Add Watch

  • Now you have its calculated value in the Watch window. (Usually pops up at the bottom)

  • You can use Quick Watch (Shift F9) if you want its value once.

  • Related