取以下函数:

DataTable go() {
    return someTableAdapter.getSomeData();
}

当我在这个函数中设置断点时,是否有可能检查返回值?Go()直接耦合到.aspx页面中的数据网格。

检查返回数据表的唯一方法是使用临时变量。然而,这有点不方便。没有别的办法了吗?


当前回答

根据微软的说法,没有办法用托管代码可靠地实现这一点。这是他们意识到并正在努力解决的问题:

For those out there who have experience debugging native C++ or VB6 code, you may have used a feature where function return values are provided for you in the Autos window. Unfortunately, this functionality does not exist for managed code. While you can work around this issue by assigning the return values to a local variable, this is not as convenient because it requires modifying your code. In managed code, it’s a lot trickier to determine what the return value of a function you’ve stepped over. We realized that we couldn’t do the right thing consistently here and so we removed the feature rather than give you incorrect results in the debugger. However, we want to bring this back for you and our CLR and Debugger teams are looking at a number potential solutions to this problem. Unfortunately this is will not be part of Visual Studio 11.

https://connect.microsoft.com/VisualStudio/feedback/details/597933/add-a-return-pseudo-variable-to-the-visual-studio-debugger-for-net-code

其他回答

据我所知没有。请注意,如果你添加了一个变量,它将被编译器在发布版本中删除…

更新: 这个功能已经被添加到VS2013中。 您可以在自动窗口中看到返回值,或者在监视/立即窗口中使用$ReturnValue。

该值只能在函数返回后直接看到,因此访问它的最简单方法是在函数调用上设置断点,然后跳过(F10)调用。


VS2015更新:boo!不幸的是,它似乎不在VS2015 (devenv v14) VS2017更新:它回来了。(devenv v15)

使用Shift-F11走出go()方法,然后在“Autos”调试窗口中,它将显示方法调用的返回值,该方法调用刚刚弹出堆栈(在这种情况下,go()方法是你想要的)。这是Visual Studio 2005中的行为;我还没有使用Visual Studio 2008,所以我不知道这个行为是否在那个版本相同。

在VS2019中,只需打开调试->Windows->汽车窗口。在那里,你看到concat返回值如下所示:

关于Visual Studio 2015:

根据Marc Gravell目前公认的答案:

此功能已添加到Visual Studio 2013。你可以看到回报 值在自动窗口或使用$ReturnValue在手表/立即 窗口

该回答还指出,该功能在Visual Studio 2015中无法工作。这并不(完全)正确。在检查方法调用的返回值时,有以下注意事项:

必须打开遗留表达式求值器才能识别$ReturnValue(工具/选项/调试/使用遗留c#和VB表达式求值器)。否则,您可以使用$ReturnValue1。

我在Visual Studio 2015 Enterprise中进行了测试:

关闭遗留表达式求值器:只有$ReturnValue1有效 打开遗留表达式求值器:$ReturnValue和$ReturnValue1都可以工作

根据客户反馈网站,这可以在Visual Studio 2013中使用CLR 4.5.1完成。它在以前的c#版本中不可用。

(Visual Studio 2008和更早的版本支持VB.NET。C/ c++开发人员一直可以使用它。)