The requested page is not available for the requested platform. You are viewing the content for Default platform.

Create Multi-variable Declaration

Converts neighboring variable declarations of the same type into a single declaration. This refactoring is the opposite of Split Multi-variable Declaration.

Availability

Available from the context menu or via shortcuts:

  • when two or more consecutive variable declarations are selected. Declared variables should have the same type.

Example

private string TestMethod()
{string a = "Hello";
    string b = "World";
    string c = "!";
    return String.Format("{0} {1} {2}", a, b, c);
}
Private Function TestMethod() As StringDim a As String = "Hello"
    Dim b As String = "World"
    Dim c As String = "!"
    Return String.Format("{0} {1} {2}", a, b, c)
End Function

Result:

private string TestMethod()
{string a = "Hello", b = "World", c = "!";
    return String.Format("{0} {1} {2}", a, b, c);
}
Private Function TestMethod() As StringDim a As String = "Hello", b As String = "World", c As String = "!"
    Return String.Format("{0} {1}{2}", a, b, c)
End Function

Screenshot

rsCreateMultiVariableDeclarationCSharp

See Also