【问题标题】:is it possible in debugging, to know if two variables are the same object?是否可以在调试中知道两个变量是否是同一个对象?
【发布时间】:2021-11-05 10:43:36
【问题描述】:

我正在使用 Visual Studio 2019 社区,并且我有以下代码:

if(this != myOtherObject
   && anotherVariable != true)
{
     //do something
}

这里的想法是我在 if 中有各种条件。所以我想知道是否有某种调试方法可以知道它是第一个条件为真还是第二个条件等等。

如果没有,我认为可能的唯一方法是:

if(this != myOtherObject)
{
    if(anotherVariable != true)
    {
        //do something
    }
}

谢谢。

【问题讨论】:

  • 按 shift + F9,然后编写所需的代码,然后按 Enter,这有帮助吗?
  • 这行得通,非常感谢。

标签: c# visual-studio debugging


【解决方案1】:
  • 在你的条件下放置一个断点。

  • 开始调试 (F5)

  • 在您的情况下突出显示this != myOtherObject

  • 右击并选择Add Watch

  • 现在您在 Watch 窗口中获得了它的计算值。 (一般在底部弹出)

  • 如果你想要它的值一次,你可以使用Quick Watch (Shift+F9)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 2015-01-27
    • 2012-08-22
    • 2015-01-28
    • 2013-07-15
    • 1970-01-01
    • 2020-05-30
    相关资源
    最近更新 更多