简体   繁体   中英

Is it possible to inspect the return value of a function that is not saved?

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?

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(); ? 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 .

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:

例

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM