调试时,是否有办法判断对象是否为其他实例? [英] When debugging, is there a way to tell if an object is a different instance?

查看:61
本文介绍了调试时,是否有办法判断对象是否为其他实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试时,我期望两个不同的类使用同一对象实例。这两个对象的所有属性都相同,但是它们是两个不同的实例。

When debugging, I was expecting two different classes to be using the same instance of an object. All of the properties were the same for these two objects, but they were two different instances. Is there a way to tell that in the VS debugger?

为了肯定地说,我能够在类中添加一个字段:

In order to tell for sure, I was able to add a field to the class:

private string someId = Guid.NewGuid().ToString();

然后,在调试时,我至少可以针对两个实例分别查看该字段。

Then, when debugging, I could at least look at that field for each of the two instances. Is there a better way that wouldn't involve having to create this dummy ID field?

推荐答案

在调试时,请在本地窗口中找到更好的方法,而不必创建此虚拟ID字段? ,右键单击该实例,然后选择生成对象ID。

When debugging, in the Locals window, right-click on the instance and select "Make Object ID".

这将添加该实例唯一的编号,只要您看到此$ b $就会显示该编号。调试器中的b实例(在工具提示以及监视窗口中)。

This will add number that is unique for this instance which is displayed whenever you see this instance in the debugger (in tool-tips as well as in the watch window).

这篇关于调试时,是否有办法判断对象是否为其他实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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