Reputation: 17525
I have a line of code like this
return foo(barIn);
If I place a breakpoint on the line can I inspect the returned value of foo(barIn) without stepping into foo? I can rewrite the code to
var result = foo(barIn);
return result;
but I'd like the convenience of not rewriting and not stepping away from the current code.
========== EDIT ==========
The four initial answers are interesting (thanks) but they do not actually answer my question. Let me try to be clearer.
In this method
public string functionA()
{
return functionB();
}
is there a way in Visual Studio 2012 to place a break point on the line "return functionB();" and inspect the return value of functionB without stepping into functionB, re-running functionB, or rewriting functionA?
Upvotes: 3
Views: 473
Reputation: 37222
No, you cannot meet this exact behaviour. See Can I find out the return value before returning while debugging in Visual Studio. The closest you can get is:
If foo
is idempotent (i.e. it does not have any side-effects), then you can add a watch to foo(barIn)
.
If it does have side-effects, then put your breakpoint on the return
, and then step-out (Shift+F11 by default) of the function and inspect the variable that the result of the function is assigned to.
Upvotes: 1
Reputation: 13296
You can see the return value in the watch window if you write foo(barIn) in there, however this will cause your foo method to be called twice and sometimes it is not what you want to happen, so getting the value to a variable and return it is the best way. You can always step into foo if you have the code.
Upvotes: 0
Reputation: 13720
You can add a watch or quick watch of foo(barIn)
to see the result. Just highlight it and right click. There are options in the context menu while debugging. Just be careful if running that method twice causes unwanted effects compared to once.
Upvotes: 0
Reputation: 1142
You can always use F11
to step into the function and then F10
to go through the function and see what it returns.
Upvotes: 0