开发者

When debugging in Visual studio, can you see what is being returned from a method?

I have a method like:

object bibble()
{
  return GetFishsticks();
}

I step through the code until the return line, and press F10 to step to the next line... so the selected line is on the }

I'd like to see what's being returned, but I can't figure out how. Is there a way to see it?

Edit (by Doc Brown): this is bothering me, too, sometimes: is there a wa开发者_运维技巧y to inspect the return value without changing the code and without calling GetFishsticks again, to avoid possible side effects?


Do it like this...

object bibble()
{ 
    object fishSticks = GetFishsticks();
    return fishSticks;
}

Now you can put a breakpint on the return statement.


In C# it isn´t possible (as others already mentioned) without defining a variable to store the return value. But VB.NET provides such functionality due to VB6 legacy support. Take a look at this blog.


You could step one line further (or step out) and see what the function that called bibble receives.


SLC, you can copy the whole method call with its parameters inside the Watch window, I just did it while debugging and works like a charm.


If you've breaked right after the method call and it has no side-effects or mutable state that affects the outcome of multiple calls you could call it again in the immediate window? I.e. type "GetFishsticks()" in the immediate window. Just be aware that execution needs to be stopped in the same stack-frame as where you do the call.


Maybe use the Immediate Window?

I know you can use the Immediate Window for get a value, but I don't know if it also works for method, but it would be easy find out.

Edited: I just made a test, and it works fine. Just write the GetFishSticks() in the Immediate Window, and press enter, and the result will be displayed below.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜