简体   繁体   中英

How to see method return value which is not being stored with the debugger

In Visual Studio 2013 how i can find out the value returned by a method which is not being stored anywhere.

Lets assume the methods are in a DLL which i don't have the source code so i cannot set a break point at the return line.

Example Use Case 1:

if(GetEnumResponse() == MyEnums.MyValue)
{
   // Do Stuff
}

Example Use Case 2:

var Response = (MyResponse)GetResponse();

In example 1, if im expecting the condition to be true but it is false, how can i use the debugger to find out what the result of GetEnumResponse() is?

In example 2, if the cast is causing an invalid cast exception how can i view what the result of GetResponse() is?

The simplest solution is to change how you call the methods to put the return value into a local variable which you can interrogate.

Case 1:

var result = GetEnumResponse();
if (result == MyEnums.MyValue)
{
   // Do Stuff
}

Case 2:

var result = GetResponse();
var Response = (MyResponse)result;

You can even leave this code in production if you want as it is functionally equivalent to what you have now.

You can use the Immediate (Debug -> Windows -> Immediate) in Visual Studio. Here you can evaluate expressions and see the result.

The return value of a function is displayed in the Autos tab or you can use the $ResultValue in the immediate window when the function has returned.

See points 6 and 7 on this blog post about seeing function return values in the debugger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM