Calling Methods From Watch Window

By | December 31, 2010

Watch windows is one of most commonly used debugging tool with Visual Studio. We generally used to explore the objects, values, properties and other nested objects as a tree structure. Most of the time we used watch window to only view the values or change the current object properties values to see the effects of changed object during debugging  but  we can call a methods from watch window as well. If you are exploring some objects inside watch window, you can simple call any of the methods for that object inside watch window.

MethodCall1

As you can see from the above image, when you have typed stud object, you are able to access all the properties and methods that is accessible by the original object.

As for example, you can  pass the proper marks inside AddMarks() methods to get the result details as shown in below image.

MethodCall2

Here is another Tricks, you can use some “temp” variable to store those data. But you have to declare the variable at “Immediate Window”.

So, just declare a variable in “immediate window” and used it inside watch window as shown in below snaps

MethodCall3

As addition you can used the same variable to do some additional operation  also.

MethodCall4

While calling some methods from watch window, please make sure the execution time for the methods should be less enough ( approx. less than 10 sec ). Otherwise you will get exception on evaluation time out.

I will request you to read one of my previous blog post where I have gave such 10 nice must known tips on Watch Window.

10 Tips you should know about “Watch Window” While debugging in Visual Studio