Reputation: 449
While stepping through in Visual Studio 2013 debugger, is there a way to find out, for a currently watched variable, which other variable/field is it currently referencing?
In a classic example below, is it possible to determine at the last line, that f2.bar is actually referencing f1.bar? Alternatively, would there be a quick way to list all by reference variable currently pointing to this value?
public class Foo
{
public string bar;
}
var f1 = new Foo();
var f2 = f1;
f2.bar = "mine";
f1.bar = "this";
Console.WriteLine(f2.bar);
f1.bar = "mine";
f2.bar = "this";
Console.WriteLine(f1.bar);
outcome:
> this
> this
Upvotes: 2
Views: 46
Reputation: 73442
If I understand correctly, You can use the Make Object ID feature.
All you have to do is give the object Id for f1
earlier at some point in debugging. Later you can inspect the f2
-- if f2
points to the same f1
debugger will show you the object id which was created with f1
, otherwise no.
In other words "Make Object ID" will tell you whether you're looking at the same reference or not.
Upvotes: 2