This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

VS 2013+

Viewing Return Values

When debugging code that calls methods with return values, it is very useful to be able to quickly determine the values generated. Visual Studio makes this very simple using the Autos pane or the immediate window.

Return Values

With Visual Studio 2012 and earlier versions, it was not straight forward to find the value returned by a method unless that value was assigned to a variable and the variable's value interrogated. Although adding a variable is a simple task, this would interrupt your debugging session, which could decrease productivity.

Visual Studio 2013 fixes this problem with a simple modification to the Autos window and the availability of a special variable that you can use within the Immediate window. To find the return value of a method, step through the code and over the method call, so the line following the method that you wish to interrogate is highlighted. The Autos window will display the return value alongside a description of the method called. To make it easier to spot, an arrow icon indicates a return value.

If you are using the Immediate window, you can find the last return value generated using the $ReturnValue variable. Both ways to obtain the value are shown in the image below. In this case the call to GenerateMessage has been stepped over. The method's result is used directly without being assigned to a variable. The value is shown at the top of the Autos list, which appears at the bottom-left. At the bottom-right, the Immediate window has been used to obtain the value from the variable.

Visual Studio Return Value

The Autos window also works when you make nested calls in a single statement, allowing you to find the return values of all of the methods. You can see this in the second image, below. Each of the three methods executed generates a single row in the Autos list.

Visual Studio Nested Return Values

3 February 2016