Debug return value

You can set a breakpoint on the line of the return statement with the method. Then right-click the breakpoint and select 'When Hit...'. In here you can select to display a message or run a macro. For this we'll print a message that will be shown in the Output Window. For example if you have following code:

public double ReturnValue()
{
    var x = 3;
    var y = 4;
    //x and y can of course be non-constant vars too
    return Calculate(x, y);
}

public static double Calculate(int x, int y)
{
    return x * x + y * y;
}

If you set a breakpoint on the line "return Calculate(x, y);", right-click it and choose 'When Hit...' and choose this as message:

Value is : {Calculate(x, y)}

In this case the Output Window will display:

Value is : 25.0

Hope this helps!

Update:

This also works for your example with the names, methods:

public string GetFirst()
{
    return "Bill";
}

public string GetLast()
{
    return "Gates";
}

public string GetFull()
{
    return GetFirst() + " " + GetLast();
}

Place the breakpoint on the return statement in the GetFull() method and do the same as before. The message-body now looks like this:

Fullname is: {GetFirst() + " " + GetLast()}

And the Output Window will show:

Fullname is: "Bill Gates"


Simply when you debug the code, when return value has evaluated, do one of these :

1- type $ReturnValue in immediate window

2- watch $ReturnValue in watch window

enter image description here


See this: https://connect.microsoft.com/VisualStudio/feedback/details/555859/see-return-value-in-managed-code (and you can upvote it)

Also there is a comment there from a guy who developed a plugin for VS to support that.

Upd. Tried that plugin. Looks great for now.


This was added in Visual Studio 2013:

The return value(s) get displayed in the “Autos Windows” (Debug->Windows->Autos) and you can also use the pseudo variable “$ReturnValue” in the Watch and/or Immediate window to fetch the last function’s return value.

http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx