Refactoring - Creating Inline Variables

From RAD Studio
Jump to: navigation, search

Go Up to Refactoring Procedures Index


This topic explains how to use the "Inline variable" operation.

To create an inline variable:

  1. Select the local variable in the Code Editor.
  2. On the main menu, choose Refactor > Inline variable.

    Tip: Alternatively, you can choose Refactor > Inline variable on the context menu.

    The resulting dialog reports the number of variable occurrences that the Inline Variable command will be applied to.
  3. Click OK to complete refactoring.

Warning: The variable that you select for creating an inline variable, should not be updated later in the source code. If it is, the following error message will display: "Variable index is accessed for writing."

For example, if you use the Inline Variable refactoring command on the local variable index shown below:

public void findIndex() {
  int index = 2;
  System.Console.Writeline("Index is: {0}", index);
  }

then the following refactoring occurs:

public void findIndex() {
   System.Console.Writeline("Index is: {0}", 2);
}

See Also