I have following code snipped:
...
var tpc = new ThirtPartyClass();
tpc.ExecuteCommand();
tpc.ExecuteCommand();
...
The ExecuteCommand() method returns a int value with some information. For debugging, I want to know this return values. But I don't want to assign the result to a variable (var result = tpc.ExecuteCommand()).
Is there in VisualStudio 2010 a possibility during debugging, to inspect this return value without assign it to a temporary variable?
Thanks in advance for your suggestions
edit: Finally, this function has been added to VS2013
how can I store and use the return value in a variable? you can easily do var ddResult = formatDateToString(); the return value dd will now be in ddResult.
There are 2 places where we can see the method return value: In the Debugger Immediate window, using the $ReturnValue keyword. To open the Immediate window while debugging, choose Debug -> Windows -> Immediate (or press keyboard shortcut: Ctrl + Alt + I).
return isn't like a function or a variable that gives you a value, it only takes values. You put it in a function, and whatever you return is what you get when you use the function later on. It's always the last thing a function does, when it returns, it stops executing.
If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed. In this case, the return value of the called function is undefined.
You can do that with IntelliTrace in VS2010, by switching to the "Calls View" then checking the Autos window:
But even without that, don't worry about it; if you don't use the variable (except by looking in the debugger when paused), then in a release build it will be removed and replaced with just a "pop" (which is what you get if you don't catch the return value in the first place).
So:
static void Main()
{
int i = SomeMethod();
}
Compiles as:
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 8
L_0000: call int32 Program::SomeMethod()
L_0005: pop
L_0006: ret
}
note no .locals
and no stloc
.
For Resharper, use:
// ReSharper disable UnusedVariable
int i = SomeMethod();
// ReSharper restore UnusedVariable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With