greenoldman
greenoldman

Reputation: 21082

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 (i.e. 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).

Upvotes: 3

Views: 6253

Answers (1)

sll
sll

Reputation: 62544

  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

Upvotes: 5

Related Questions