唯一标识引用类型在调试器 [英] Uniquely Identifying Reference Types in the Debugger

查看:154
本文介绍了唯一标识引用类型在调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自一个C ++的背景,所以道歉,如果这是一种思维非C#的方式,但我只需要知道。 :)

I come from a C++ background, so apologies if this is a non-C# way of thinking, but I just need to know. :)

在C ++中,如果我有两个指针,我想知道他们是否指向同样的事情,我可以看在内存/监视窗口,看看他们的价值 - 看看他们都指向相同的内存空间。

In C++ if I have two pointers, and I want to know if they point to the same thing, I can look in the memory/watch window and see their value - to see if they are pointing to the same memory space.

在C#中,我一直没能找到类似的规定。具有完全相同值的一个引用类型实际上可能是完全相同的对象,也可能是一些完全不同的。

In C#, I haven't been able to find something along those lines. One reference type with exactly the same values could in fact be the exact same object, or it could be something wildly different.

有我的方式来看到这种信息在C#中?也许是某种相当于&放大器;运营商在监视窗口或一些这样?

Is there a way for me to see this kind of information in C#? Perhaps some kind of equivalent to the & operator for the watch window or some such?

推荐答案

您在找什么是对象ID的。对于在调试任何referenc类型你可以右键点击并说:使对象ID。这将一个#后缀添加到时该实例显示在调试器值列。您还可以添加#1,#2,等等,以监视窗口的任何时间以后再见到他们。

What you're looking for are object id's. For any referenc type in the debugger you can right click and say "Make Object ID". This will add a # suffix to the value column whenever that instance is displayed in the debugger. You can also add #1, #2, etc ... to the watch window to see them again any time later.

步骤0 - 运行此code

Step 0 - Run this code

static void Main(string[] args)
{
    var x = "a string";
    var y = x;
    System.Diagnostics.Debugger.Break();
}

第1步 - 单击右键,选择使对象ID

Step 1 - Right Click and select "Make Object Id"

第2步 - 现在实例显示与1#后缀。注:我什么也没做这一步特别。点击之后,立即使对象ID的两个的更新,因为它们指的是同一个实例,显示1#后缀行。

Step 2 - Instances now display with the 1# suffix. Note: I did nothing special in this step. Immediately after clicking "Make Object Id" both rows updated to display the 1# suffix since they refer to the same instance.

第3步 - 通过添加1#监视窗口中看到他们在任何时间

Step 3 - See them at any time by adding 1# to the watch window

这篇关于唯一标识引用类型在调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆