Widen Scope (Promote to Field)
Purpose
Converts a variable declared within a method to a private field.
Availability
Available in a variable declaration within a method.
Usage
Place the caret in a variable declaration.
Note
The blinking cursor shows the caret’s position at which the Refactoring is available.
- Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
- Select Widen Scope (promote to field) from the menu.
After execution, this refactoring moves the variable declaration out of the current methods and converts it to a field.
class TestClass {
string completeUrl;
private void SetUrl(string url) {
completeUrl = string.Format("http://{0}", url);
}
}
Note
The default visibility modifier of the generated member is configured on the Editor | <Language> | Scope Options options page. Refer to the Scope topic for details.
See Also