Skip to main content

Inline Result

Replaces final assignments to the temporary variable with a statement that immediately returns the value.

#Purpose

This refactoring can help you simplify your code by removing an unnecessary temporary variable.

#Availability

Available from the context menu or via shortcuts:

  • when the caret is on a local variable whose value is returned by this method.

    Note

    This refactoring is available even if assignments and corresponding return statements appear in conditional branches.

    The referenced variable shouldn’t have cumulative assignments (those that use this variable in the right-hand section).

#Note

  • The local variable declaration is removed as the result of Inline Result.

#Example

private int TestMethod(int param1)
{
    int res = 25+param1;
    return res;
}
Private Function TestMethod(ByVal param1 As Integer) As Integer
    Dim res As Integer = 25 + param1
    Return res
End Function

Result:

private int TestMethod(int param1)
{
    return 25 + param1;
}
Private Function TestMethod(ByVal param1 As Integer) As Integer
    Return 25 + param1
End Function

#Screenshot

rsInlineResultCSharp

See Also