Widen Scope (promote to field)

Converts a local variable to a field variable, activates Linked Identifiers for the field references, and drops a marker onto the initial code line.

Availability

Available from the context menu or via shortcuts:

  • when the caret is on a variable declared within a class member (for instance, within a method). The selected variable is moved outside of the parent member, so that it becomes available to all class members.

Example

private string TestMethod(string param1)
{
    string MyString = "My string";
    return MyString + param1;
}
Private Function TestMethod(ByVal param1 As String) As String
    Dim MyString As String = "My string"
    Return MyString + param1
End Function

Result:

private string _MyString;
private string TestMethod(string param1)
{
    _MyString = "My string";
    return _MyString + param1;
}
Private _myString As String
Private Function TestMethod(ByVal param1 As String) As String
    _myString = "My string"
    Return _myString + param1
End Function

Animation

rsWidenScopePromoteToField

See Also