Take the following function:
DataTable go() {
return someTableAdapter.getSomeData();
}
When I set a breakpoint in this function, is there a possibility to inspect the returned value? go()
is directly coupled to a datagrid in an .aspx
page.
The only way to inspect the returned datatable is to use a temporary variable. However, that's a bit inconvenient. Isn't there another way?
Opening the Debug → Autos window gets you close. It won't show the actual return value, but it will show what was evaluated in the return statement.
According to the currently accepted answer by Marc Gravell:
That answer also stated that this functionality does not work in Visual Studio 2015. This is not (entirely) true. On Examine return values of method calls there is the following note:
I tested this in Visual Studio 2015 Enterprise:
Step out of the go() method using Shift-F11, and then in the "Autos" debug window it will show the return value of the method call which just popped off the stack (in this case, the go() method which is what you want). This is the behaviour in Visual Studio 2005; I haven't used Visual Studio 2008 so I don't know if this behaves the same way in that version.
The only way I know is to place a breakpoint on the return line and then call the Quick Watch window and enter the returned expression:
But this only works if the call does not change the state of any object (since there will be a second call to the same method when you will resume the execution).
Microsoft Visual C++ used to do this, but Visual Studio doesn't AFAIK.. :(
I agree that this is a very useful thing to have: not only seeing the return value of the method before stepping out of it, but also seeing the return value of methods I just stepped over. I implemented it as part of a commercial extension to Visual Studio called "OzCode".
With it, you can view method return values right on the code editor, as sort of a HUD-display:
For more information, please see this video.