Skip to main content

Collapse/Expand Method

Purpose

Collapses a simple method body onto a single line and vice versa. Single-line methods make your code more compact, in other hand, they can decrease code readability.

Availability

Available when the caret is at the beginning of a method declaration or on the method name, provided that the method body consists of a single statement.

Usage

  1. Place the caret on the name of a suitable method.

    Note

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

    public float USDtoEUR(float amount) {
        return amount / GetCurrencyRate();
    }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Collapse Method from the menu (Expand Method if you are expanding the method).

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

public float USDtoEUR(float amount) { return amount / GetCurrencyRate(); }
See Also