Calling Methods From Watch Window

Calling Methods From Watch Window

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

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.