Is it possible to inspect the return value of a fu

2019-07-10 04:43发布

This is a slight variation of this question. If I have a function that performs an action that returns a value but I did not capture that value in a variable, is there any way I can get that value while stepping through with the debugger without running the function a 2nd time in the immediate window?

A practical example

using (SqlConnection cnSqlConnect = OpenConnection(ConnectionString))
using (SqlCommand sqlCmd = new SqlCommand(command, cnSqlConnect))
{
    sqlCmd.ExecuteNonQuery();
}

Is there any way to get the value of sqlCmd.ExecuteNonQuery() without running it twice?

2条回答
男人必须洒脱
2楼-- · 2019-07-10 05:19

Using BugAid in Full Mode, you'll be able to see the value that ExecuteNonQuery returned right after you step over it, by using its Statement Visualization feature.

BugAid visualizes the values of every method call, even if that value is not assigned to a variable. It does this without re-evaluating the function (it never causes the method to be executed twice).

For example:

Example

Full disclosure: I am a co-creator of BugAid.

查看更多
在下西门庆
3楼-- · 2019-07-10 05:30

Yes there is!

  1. Break on the function before it executes.
  2. From the Command Window run the line of code you stopped on, prepended with a ? to view the results. Like this: ? sqlCmd.ExecuteNonQuery();
  3. Manually drag the yellow pointer showing the next line of code to be executed down to the next line, skpping over the code that you ran in the command window.

This will have the effect of only executing your code once and will let you view the result.

For more information see the Basics of using the Command Window.

查看更多
登录 后发表回答