简体   繁体   中英

Inspecting the returned value of a function on the return line of a method in Visual Studio

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?

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 (ie 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.

您可以随时使用F11进入该功能,然后使用F10进入该功能并查看它返回的内容。

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.

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.

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