Freigeben über


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

  1. Create a C# or C++ console application.

  2. 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;
    }
    
  3. Set breakpoints at the calls to Method1 and Method2 in the main method.

  4. On the Debug menu, choose Start Debugging (keyboard: F5) to start debugging and break at the Method1 call.

  5. Choose Debug, Step Into (keyboard : F10) to enter Method1.

  6. Choose Debug, StepOver (keyboard: F11) to step over Method1’s first line of code.

  7. 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)

    Method return values in the Autos window

  8. Choose Debug, Continue (keyboard: F5) to continue execution to the call to Method2.

  9. Step into Method2.

  10. Step over the return statement.

  11. Note that the Autos window displays the return value of the Five method (the value that is directly returned by Method2).

    Return value in the Autos window

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).