Examine return values of method calls
In the Autos window, you can examine the return values of the .NET Framework and C++ methods when you step over or out of a method call. This functionality is useful when the result of a method call is not stored in a local variable, such as when a method is used as a parameter or return value of another method.
Contents
View method return values in the Autos window
View the .NET Framework method return values in Immediate and watch windows
View method return values in the Autos window
Create a C# or C++ console application.
Replace the C# Main method or the C++ _tmain method with the following code.
//static void Main(string[] args) { Method1(); // 1. Set a breakpoint here // 2. Then step into Method1 int y = Method2(); // 3. Set a breakpoint here // 4. Then step into Method2 static void Method1(){ // 1. Step over the following line int result = Multiply(FourTimes(Five()), Six()); // 2. Then view the return values in the Autos window } static int Method2(){ // 1. Step over the following line return Five(); // 2. Then view the return values in the Autos window } static int Multiply(int x, int y){ return x * y; } static int FourTimes(int x){ return 4 * x; } static int Five(){ return 5; } static int Six(){ return 6; }
void Method1(); int Method2(); int Multiply(int x, int y); int FourTimes(int x); int Five(); int Six(); int _tmain(int argc, _TCHAR* argv[]) { Method1(); // 1. Set a breakpoint here // 2. Then step into Method1 int x = Method2(); // 3. Set a breakpoint here // 4. Then step into Method2 } void Method1(){ // 1. Step over the following line int result = Multiply(FourTimes(Five()), Six()); // 2. Then view the return values in the Autos window } int Method2(){ // 1. Step over the following line return Five(); // 2. Then view the return values in the Autos window } int Multiply(int x, int y){ return x * y; } int FourTimes(int x){ return 4 * x; } int Five(){ return Six(); } int Six(){ return 6; }
Set breakpoints at the calls to Method1 and Method2 in the main method.
On the Debug menu, choose Start Debugging (keyboard: F5) to start debugging and break at the Method1 call.
Choose Debug, Step Into (keyboard : F10) to enter Method1.
Choose Debug, StepOver (keyboard: F11) to step over Method1’s first line of code.
In the Autos window, note that the return values of the Multiply, FourTimes, Five, and Six methods are displayed and include the return value icon. (To open the Autos window, choose Debug, Windows, Autos, or press Ctrl + Alt + V, A)
Choose Debug, Continue (keyboard: F5) to continue execution to the call to Method2.
Step into Method2.
Step over the return statement.
Note that the Autos window displays the return value of the Five method (the value that is directly returned by Method2).
View the .NET Framework method return values in Immediate and watch windows
You can also examine the return value of a .NET Framework method call by typing $ReturnValue in the Immediate window or a watch window after you have stepped over or out of the method call. To open the Immediate window, choose Debug, Windows, Immediate (keyboard: Ctrl + Alt + I).