取以下函数:

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

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

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


当前回答

是的,有一个很好的方法。一个显著的缺点是你必须等待5年,也许6年。自从我看到你在2008年11月发的帖子,我建议你waaaaaa…

……aaaait。瞧!只是为了你,微软发布了最新的Visual Studio 2013,它是在调试模式下运行时从菜单中访问的默认功能(菜单debug→Windows→Autos)。

其他回答

是的,通过切换到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 2015中不能正常工作,但是通过在方法的最后一行上放置断点并按F10,它将把返回值的所有表达式放入locals窗口。

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

someTableAdapter.getSomeData();

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

进入“工具→选项”、“IntelliTrace”菜单,修改设置,收集事件和呼叫信息。

您可以返回到前面的调用事件(Ctrl + Shift + F11),并在autos窗口中看到方法调用返回的临时值作为方法名的子值。

这并没有显示您所在方法的返回值。它只显示当前方法中调用的最后一个方法的返回值。

所以,对于

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

因为它会显示someTableAdapter.getSomeData()的返回值。

但不是为了:

int go(){return 100 * 99;}

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