Refactoring - Creating Inline Variables
From RAD Studio XE
Go Up to Refactoring Applications Index
This topic explains how to use the "Inline variable" operation.
To create an inline variable:
- Select the local variable in the Code Editor.
- 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. - 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);
}