Skip to main content

Convert to Property with Backing Field

Purpose

Converts an auto-implemented property to a property with the private field and fully described accessors. This prepares the property for the extension.

Note

This Refactoring is opposite to Convert to Auto-implemented Property.

Availability

Available when the caret is on a property declaration statement. The property should be auto-implemented.

Usage

  1. Place the caret on a property declaration statement.

    Note

    The blinking cursor shows the caret’s position at which the Refactoring is available.

    public string A { get; set; }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Convert to Property with Backing Field from the menu.

After execution, the Refactoring adds the intermediate private variable along with the getter and setter bodies.

string a;
public string A {
    get {
        return a;
    }
    set {
        a = value;
    }
}
See Also