简体   繁体   中英

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.

The question is how to do the same (ie inspect object) but not any argument or variable, but "this" 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).

  1. Quick Watch Window

    • Right click in any place of window
    • In menu select "Quick Watch"
    • In text field enter this
    • Press OK
  2. Add Watch Window

    • Visual Studio menu -> Debug -> Windows -> Watch -> Watch 1
    • In opened Watch WIndow type in Name field this and press Enter
  3. Immediate Window

    • Visual Studio menu -> Debug -> Windows -> Immediate Window
    • Type this and press Enter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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