Collapse Accessors

Purpose

Collapses accessors' code into a single line to make code more compact. However, single-line accessors can decrease readability.

Availability

Available when the caret is on a property name or get/set statement inside the property declaration (both accessors should consist of a single statement).

Usage

  1. Place the caret on a property name or get/set statement.

    Note

    The blinking cursor shows the caret's position at which the Code Formatter is available.

    public int A {
        get {
            return a;
        }
        set {
            a = value;
        }
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Collapse Accessors from the menu.

After executing refactoring, the Code Formatter removes the line breaks and converts property accessors to a single-line form.

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