To create an inline variable:
- Select the local variable in the Editor.
- On the main menu, choose RefactoringInline variable
Tip: Alternatively, you can choose Refactoring->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);
}