取以下函数:

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

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

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


当前回答

前。net时代的老把戏:打开寄存器窗口并查看EAX寄存器的值。它包含最后调用的函数的返回值。

其他回答

您可以尝试选择“someTableAdapter.getSomeData();”,右键单击它,然后选择快速观察。

我知道的唯一方法是在返回行上放置一个断点,然后调用Quick Watch窗口并输入返回的表达式:

someTableAdapter.getSomeData();

但这只有在调用不改变任何对象的状态时才有效(因为当您恢复执行时,将会对同一方法进行第二次调用)。

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

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

关于Visual Studio 2015:

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

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

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

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

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

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

是的,通过切换到VB.NET。P)你刚才说了“Visual Studio”。,)

在我的记忆中(从Visual Basic到VB.NET的所有版本),您可以简单地查询函数名。它像一个局部变量一样“起作用”,在函数开始时隐式声明,它的当前值也被用作函数通过非返回语句退出时的返回值(即Exit function或只是falling through),当然,当使用return语句时。

它还被设置为return语句的表达式。就像局部变量一样,它的值可以在函数内部的任何执行点检查(包括在return语句执行之后)。c#没有,也应该有。

That little VB.NET feature (plus the Exit Function statement which it enables - another feature C# doesn't have and should) is very useful in a form of defensive programming I practice where I always initialize the function name to the failure/default value as the first statement. Then, at any failure point (which normally occurs much more often than success points), I can simply call the Exit Function statement (i.e. without having to duplicate the failure / default expression or even a constant/variable name).