9

Possible Duplicate:
Can I find out the return value before returning while debugging in Visual Studio
VS get returned value in C# code?

In Visual Studio 2010, is there a way to check the value that a method is about to return? I often find myself changing code like:

return myComplexOp(someOtherComplexOp(foo));

to

var ret = myComplexOp(someOtherComplexOp(foo));
return ret;

just to make it easier to debug? Is there an easier way?

Community
  • 1
  • 1
JoelFan
  • 37,465
  • 35
  • 132
  • 205
  • +1; this bugs(!) me a lot too. – Aasmund Eldhuset Oct 03 '11 at 19:49
  • Here's a [question](http://stackoverflow.com/questions/268048/can-i-find-out-the-return-value-before-returning-while-debugging-in-visual-studio) asking the same thing for VS (not just 2010) specifically for C#. The short answer seems to be no for C#, but yes for C++ (with some having trouble successfully doing it). – David Alber Oct 03 '11 at 19:55
  • +1 just because I hate this too. – Paul Walls Oct 03 '11 at 22:45

2 Answers2

4

With C++ code I am stepping out of the function (Shift + F11) and open Autos window (Debug, Windows, Autos). At this point it shows recently returned value like this:

Debug, Windows, Autos

It's not the most convenient thing, but it's still something. At least you can see the returned value without altering code as mentioned in original post.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
0

If you enable the Registers Windows, you can check EAX which should hold the return value.

Mike Kwan
  • 24,123
  • 12
  • 63
  • 96