[英]How do you determine the value of a return statement that isn't stored in a variable?
The code I am working with has many recursive method calls that return the results of the method directly without storing it into a variable. 我正在使用的代码有许多递归方法调用,它们直接返回方法的结果而不将其存储到变量中。
public bool foo()
{
return bar();
}
public bool bar()
{
return infinitMethodCalls();
}
As a result, debugging is a pain. 因此,调试很痛苦。 How can I determine the value returned by bar() without using a temp variable or following the endless method calls?
如何在不使用临时变量或遵循无限方法调用的情况下确定bar()返回的值?
temp variable example: 临时变量示例:
public bool foo()
{
return result = bar();
}
The code I am working with is mostly written this way. 我正在使用的代码主要以这种方式编写。
This depends on the version of VS you are using. 这取决于您使用的VS版本。
For Visual Studio 2013 you can show the "Autos" window, it dynamically displays all return values of functions you step over while debugging. 对于Visual Studio 2013,您可以显示“Autos”窗口,它会动态显示您在调试时跳过的所有函数的返回值。 You can find the Autos Window here: Debug => Windows => Autos in your VS Menu.
您可以在此处找到Autos Window:在VS菜单中调试=> Windows => Autos。 (For more info see here )
(有关详细信息,请参阅此处 )
For Visual Studio 2010 for example you can use IntelliTraces "Calls View" as answered here 对于例如,你可以使用IntelliTraces Visual Studio 2010的“电话查看”作为回答这里
What about using a trace statement. 那么使用trace语句呢? I'm assuming you want to know what the result of each call on the call stack is when debugging the recursion.
我假设你想知道在调试递归时调用堆栈上每次调用的结果是什么。
Note: Having the trace statement at the top of the function will order the output, to the console, from first to last. 注意:在函数顶部使用trace语句会将输出从头到尾排序到控制台。
For example: 例如:
void Factorial(int n) {
Trace.WriteLine(n);
if (n == 0)
return 1;
else
return (n * factorial(n-1));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.