取以下函数:

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

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

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


当前回答

是的,通过切换到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).

其他回答

是的,通过切换到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).

我同意这是一件非常有用的事情:不仅可以在退出方法之前看到它的返回值,而且还可以看到我刚刚跳过的方法的返回值。我把它作为Visual Studio商业扩展“OzCode”的一部分来实现。

有了它,你可以直接在代码编辑器中查看方法的返回值,就像一种hud显示:

要了解更多信息,请观看这个视频。

如果中间窗口没有设置标志或其他变量,而只是返回一些东西,您也可以要求在中间窗口中计算值。

将返回表达式拖放到观察窗口中。

例如,在语句中

return someTableAdapter.getSomeData();

拖放

someTableAdapter.getSomeData()

进入一个观察窗口,你会看到数值。

你可以对任何表达式这样做。

我想在Visual Studio 2015中扩展PascalK的答案,因为有一个隐藏的特性没有在检查方法调用的返回值中记录。

如果有嵌套函数调用,则会自动创建伪变量$ResultValueX,其中X指的是函数调用顺序。因此,如果你有一个像Multiply(Five(), Six())这样的调用,则会创建以下伪变量:

Five()     | $ResultValue1 = 5
Six()      | $ResultValue2 = 6
Multiply() | $ResultValue3 = 30