检查返回值而不将其赋值给变量 [英] Inspect return value without assign it to a variable
问题描述
我有以下代码剪切:
...
var tpc = new ThirtPartyClass();
tpc.ExecuteCommand();
tpc.ExecuteCommand();
...
ExecuteCommand()方法返回一个含有一些信息的int值。
对于调试,我想知道这个返回值。但是我不想将结果分配给变量(var result = 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()).
VisualStudio 2010中有可能在调试期间,检查此返回值而不分配给临时变量?
Is there in VisualStudio 2010 a possibility during debugging, to inspect this return value without assign it to a temporary variable?
提前感谢您的建议
编辑:最后,此功能已添加到 VS2013
edit: Finally, this function has been added to VS2013
推荐答案
IntelliTrace在VS2010中,通过切换到通话视图,然后选中自动窗口:
You can do that with IntelliTrace in VS2010, by switching to the "Calls View" then checking the Autos window:
但即使没有,不要担心;如果您不使用该变量(除非在暂停时查看调试器),那么在发布版本中,它将被删除并替换为只有一个pop(这是你得到的,如果你没有收到回报价值在第一位)。
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).
所以:
static void Main()
{
int i = SomeMethod();
}
编译为:
.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
。
note no .locals
and no stloc
.
对于Resharper,使用:
For Resharper, use:
// ReSharper disable UnusedVariable
int i = SomeMethod();
// ReSharper restore UnusedVariable
这篇关于检查返回值而不将其赋值给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!