Mark Gilbert's Blog

Science and technology, served light and fluffy.

Hey, Watch this!

I’m sure I am the second-to-last person* to realize this about the Visual Studio Watch window, but not only can you have it monitor public properties of an object, it can monitor private ones as well.

WatchWindow

I think the barrier to me realizing that it could see the values for the public methods is that over half the time I’m relying on IntelliSense to drop something in.  IntelliSense, of course, will only show the public properties of an object, or in the very least it won’t show private ones.  The other day, I tried pasting in something like MyObject._MyPrivateVariable, and sure enough it worked.  I didn’t realize what I had done until a few seconds after I hit Ctrl-V.  When I had, I deleted it and manually typed the full variable reference out, just to confirm what I had done.  Sure enough, IntelliSense stopped providing any information once I had "MyObject._" entered, but completing the private member name worked.  The current value appeared immediately, and updated as the execution progressed.

This really shouldn’t have come as a surprise to me.  Had I put a watch on just "MyObject" and then expanded the + sign next to it, the private members would have shown up then.  These values also appear in the QuickWatch (available when you right-click on an object in code while you are in Debug mode) as well as in the Command Window.

It’s really cool when I get lucky and stumble onto something like this.  Then again, even a stopped watch is right twice a day.

 

* The last person will be my 9-month-old daughter when she starts programming next month.

Advertisements

October 28, 2009 - Posted by | Visual Studio/.NET

Sorry, the comment form is closed at this time.

%d bloggers like this: