Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine reference equality of two variables in different scope?

Let's say you are debugging. At one point you are in Method A, which has a parameter foo of type Foo. Later on you are in Method B, which also takes a parameter foo of type Foo.

These two variables may well be the same Foo instance, but how do you tell? Because they are in different scope, you cannot call ReferenceEquals(). Is there some way you can obtain the actual memory location the variables point to so that you can tell if they are the instance?

like image 718
David Avatar asked Sep 02 '11 15:09

David


Video Answer


1 Answers

I believe you can use the Make Object ID feature. More information on this can be found here, but to summarize:

  1. Set a BreakPoint in your code where you can get to an object variable that is in scope.
  2. Run your code and let it stop at the BreakPoint.
  3. In your Locals or Autos Window, right-click the object variable (note the Value column) and choose "Make Object ID" from the context menu.
  4. You should now see a new ID number (#) new in the Value column.

After you "mark" the object, you will see the assigned ID in the second call to Foo.

like image 52
CodeNaked Avatar answered Sep 18 '22 11:09

CodeNaked