检查返回值而不将其赋值给变量
我有以下代码剪切:
... var tpc = new ThirtPartyClass(); tpc.ExecuteCommand(); tpc.ExecuteCommand(); ...
ExecuteCommand()方法返回带有一些信息的int值。 对于调试,我想知道这个返回值。 但我不想将结果分配给变量(var result = tpc.ExecuteCommand())。
VisualStudio 2010中是否有可能在调试期间检查此返回值而不将其分配给临时变量?
提前感谢您的建议
编辑:最后,此function已添加到VS2013
您可以使用VS2010中的IntelliTrace,切换到“调用视图”,然后选中“自动”窗口:
但即便没有,也不要担心; 如果你不使用变量(除非在暂停时查看调试器),那么在发布版本中它将被删除并替换为只是一个“pop”(如果你没有收到返回,那就是你得到的)价值在第一位)。
所以:
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 }
注意没有.locals
,没有stloc
。
对于Resharper,请使用:
// ReSharper disable UnusedVariable int i = SomeMethod(); // ReSharper restore UnusedVariable
AFAICT,如果您使用BugAid,它可以显示返回值,如下图所示:
您可以在调试期间使用手表或使用即时窗口。 您可以将代码复制到即时窗口以在调试期间运行它以查看它返回的内容。 但是,它将再次执行代码以获取返回值。