HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

Can I find out the return value before returning while debugging in Visual Studio?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
whilereturnfindvaluethecanstudiodebuggingbeforevisual

Problem

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?

Solution

Not that I know of. Note that if you do add a variable, it will get removed by the compiler in release builds anyway...

Update:
This functionality has been added to VS2013.
You can see the return values in the autos windows or use $ReturnValue (or $ReturnValue1 or $returnvalue, depending on the VS version) in the watch/immediate window.

The value can only be seen directly after returning from the function, thus the easiest way to access it is by putting a breakpoint on the function call and step over (F10) the call.

Update for VS2015: boo! unfortunately, it doesn't appear to be in VS2015 (devenv v14)

Update for VS2017: it's back. (devenv v15)

Update for VS2022: In Visual Studio 2022 the name $ReturnValue in watch window works, but it needs to be added to the watch window BEFORE "return" statement is hit, not after. (according to Andrew)

Context

Stack Overflow Q#268048, score: 342

Revisions (0)

No revisions yet.