Skip to main content

Collapse/Expand Property

Purpose

Collapses the property declaration onto a single line and vice versa. Single-line properties make your code more compact. On the other hand, they can decrease code readability.

Availability

Available when the caret is on the property variable name, provided that all property accessors consist of a single statement.

Usage

  1. Place the caret on a property variable name.

    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. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Collapse Property from the menu (Expand Property - if you are expanding the property).

After execution, the Code Formatter removes the line breaks, and converts the property to a single-line form or expands it to a multiple-line form.

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