简体   繁体   English

调试时如何在 Visual Studio 中检查“这个”object?

[英]How to inspect “this” object in Visual Studio while debugging?

When you debug your program, and for example you set a breakpoint as in here:当您调试程序时,例如您在此处设置断点:

void foo(string s)
{
  (*) if (s=="bar")
  ...
}

(*) denotes breakpoint (*) 表示断点

you can move mouse cursor over "s" and inspect the content of it.您可以将鼠标 cursor 移动到“s”上并检查其内容。

The question is how to do the same (ie inspect object) but not any argument or variable, but "this" object?问题是如何做同样的事情(即检查对象)但不是任何参数或变量,而是“这个”object?

My case: I get exception at some point, I trace call stack, and let's say I would like to inspect "this" object of the 4th method of the call stack (for example).我的情况:我在某个时候遇到异常,我跟踪调用堆栈,假设我想检查调用堆栈的第四个方法的“this”object(例如)。

  1. Quick Watch Window快速手表 Window

    • Right click in any place of window在window的任意位置右键单击
    • In menu select "Quick Watch"在菜单 select“快速观察”中
    • In text field enter this在文本字段中输入this
    • Press OK按确定
  2. Add Watch Window添加手表 Window

    • Visual Studio menu -> Debug -> Windows -> Watch -> Watch 1 Visual Studio 菜单 -> Debug -> Windows -> Watch -> Watch 1
    • In opened Watch WIndow type in Name field this and press Enter在打开的手表this中输入Name字段并按 Enter
  3. Immediate Window立即 Window

    • Visual Studio menu -> Debug -> Windows -> Immediate Window Visual Studio 菜单 -> Debug -> Windows -> Immediate Window
    • Type this and press Enter键入this内容并按 Enter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM