Skip to main content

Move Initialization to Declaration

Purpose

This Refactoring combines the initialization and declaration into a single statement. This reduces the number of lines in your code and increases its readability.

Availability

Available when the caret is on a variable name in its declaration or initialization.

Usage

  1. Place the caret on a variable name in its declaration or initialization.

    Note

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

    double a;
    // ...
    a = 1.42;
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Move Initialization to Declaration from the menu.

After execution, the Refactoring moves the variable initialization to the statement at which it was declared.

double a = 1.42;
// ...
See Also