Move Declaration Near Reference

Purpose

Moves a local variable declaration to the closest point before its first usage. This increases the code readability.

Availability

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

Usage

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

    Note

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

    double a;
    // ...
    a = 42;
    // ...
    SendNumber(a);
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Move Declaration Near Reference from the menu.

After execution, the Refactoring moves the variable declaration to the closest point before its first usage.

// ...
double a;
a = 42;
// ...
SendNumber(a);

See Also