views:

197

answers:

2

Hi,

Consider the following piece of code: my code

As you can see we are on line 28. Is there any way to see the return value of the function at this point, without letting the code return to the caller function?

Foo.Bar() is a function call which generates a unique path (for example). So it's NOT constant.

Entering ?Foo.Bar() in the immidiate window doesn't work either, since that reevaluates the code:

?Foo.Bar()
"80857466"
?Foo.Bar()
"2146375101"
?Foo.Bar()
"1106609407"
?Foo.Bar()
"792759112"

In VB.NET it's possible by entering the function's name in the Watch, which will then threat it as a variable.

But in C# this is not possible, any other tips?

PS: rewriting is not an option.

+2  A: 

Assuming you are using visual studio, you could use the Immediate window. If you type Foo.Bar(); in the Immediate window you will get the result you are after, if you don't want it to re-evaluate stick a break point in the appropriate spot IE either before it evaluates the first time or in Foo.Bar() itself.

cgreeno
+3  A: 

Answer found here: http://stackoverflow.com/questions/591086/vs-get-returned-value-in-c-code

It is actually visible. Debug + Other Windows + Registers. Look at the value of EAX (RAX in x64). The value of simple integral types are returned in the EAX register. Long in EDX:EAX. Floating point in STx (XMM00 in x64).

Daniel Renshaw
Yes, but what about objects?
Snake
You're right, doesn't help much for objects. You could always go query memory at the address stored in that register but that's hardly easy! I can't find any alternative so I guess you'd have to fall back on storing the result in a variable before returning it. See the answers to the linked SO question for a link where you can ask MS to do something about this.
Daniel Renshaw
Okay, thank you :)
Snake