问题描述
我有以下代码剪断:
...
var tpc = new ThirtPartyClass();
tpc.ExecuteCommand();
tpc.ExecuteCommand();
...
的ExecuteCommand()方法返回的一些信息的int值。
。对于调试,我想知道这个返回值。但我不希望的结果分配给一个变量(VAR的结果= 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()).
有没有在2010年的VisualStudio调试过程中一种可能性,以?检查,而不把它分配给一个临时变量这个返回值
Is there in VisualStudio 2010 a possibility during debugging, to inspect this return value without assign it to a temporary variable?
在此先感谢您的建议
编辑:最后,该功能已被添加到
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:
但是,即使没有那个,不用担心它;如果你不使用变量(除了通过寻找在调试器暂停时),然后在发布版本将被删除,只用流行取代(这是你得到什么,如果你没有赶上回。首先值)
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();
}
编译如下:
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
}
请注意没有 .locals
并没有 stloc
。
ReSharper的,使用:
For Resharper, use:
// ReSharper disable UnusedVariable
int i = SomeMethod();
// ReSharper restore UnusedVariable
这篇关于检查返回值,而不把它分配给一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!