Reputation: 1577
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
Upvotes: 11
Views: 2676
Reputation: 1064004
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
Upvotes: 8
Reputation: 3213
You can use a watch or use the immediate window during debugging. You can copy code into the immediate window to run it during debugging to see what it returns. It will execute the code again to get the return value, however.
Upvotes: 1