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

与世无争的帅哥 提交于 2019-12-23 16:15:29

问题


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?


回答1:


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.




回答2:


You can always use F11 to step into the function and then F10 to go through the function and see what it returns.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/11415847/inspecting-the-returned-value-of-a-function-on-the-return-line-of-a-method-in-vi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!