查找指向Visual Studio中相同内存的所有变量 [英] Find all variables that point to the same memory in Visual Studio
问题描述
在Visual Studio 2008中,是否可以找到所有指向与另一个变量指向同一对象的变量?
In Visual Studio 2008, is there a way of finding all the variables that point to the same object as another variable?
因此,在下面的示例中,我想找出 ref1
和 ref2
都指向与 original
相同的对象.
So in the example below I would want to find out that ref1
and ref2
both point to the same object as original
.
var original = new List<string>() { "Some Data" };
var ref1 = original;
var ref2 = ref1;
基本上,我希望能够对内存中的所有变量调用 ReferenceEquals()
,然后查看所有相等的变量.除了我希望能够在VS2008 IDE中做到这一点.
Essentially I want to be able to call ReferenceEquals()
on all the variables in memory and then see all the ones that are equal. Except I want to be able to do this in the VS2008 IDE.
推荐答案
我刚刚找到了一种实现我想要的方法的方法,并将其全部移植到了VS2008中.
I just found a way of achieving what I wanted, and its all baked into VS2008.
如果在调试时将鼠标悬停在变量上,请右键单击工具提示,然后选择生成对象ID"
If you hover over a variable while you're debugging, right click on the tooltip and select 'Make Object ID'
这会给该对象一个ID(#1),该ID出现在工具提示中.因此,如果您有另一个指向相同对象的变量,它将具有相同的ID(#1).
This gives that object an id (#1) that appears in the tooltip. So if you've got another variable that points to the same object it will have the same id (#1).
这篇关于查找指向Visual Studio中相同内存的所有变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!