rhe*_*980 9 c# debugging visual-studio-2010
我有以下代码剪切:
...
var tpc = new ThirtPartyClass();
tpc.ExecuteCommand();
tpc.ExecuteCommand();
...
Run Code Online (Sandbox Code Playgroud)
ExecuteCommand()方法返回带有一些信息的int值.对于调试,我想知道这个返回值.但我不想将结果赋给变量(var result = tpc.ExecuteCommand()).
VisualStudio 2010中是否有可能在调试期间检查此返回值而不将其分配给临时变量?
提前感谢您的建议
编辑:最后,此功能已添加到VS2013
您可以使用VS2010中的IntelliTrace执行此操作,方法是切换到"调用视图",然后选中"自动"窗口:

但即便没有,也不要担心; 如果你不使用变量(暂停时查看调试器除外),那么在发布版本中它将被删除并替换为只是一个"pop"(如果你没有收到返回,那就是你得到的)价值在第一位).
所以:
static void Main()
{
int i = SomeMethod();
}
Run Code Online (Sandbox Code Playgroud)
编译为:
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 8
L_0000: call int32 Program::SomeMethod()
L_0005: pop
L_0006: ret
}
Run Code Online (Sandbox Code Playgroud)
注意不.locals,不stloc.
对于Resharper,请使用:
// ReSharper disable UnusedVariable
int i = SomeMethod();
// ReSharper restore UnusedVariable
Run Code Online (Sandbox Code Playgroud)