Move Initialization to Declaration
In This Article
Combines the declaration of a local variable with its initialization or first assignment.
#Purpose
- Having the initialization on the same line as the declaration usually makes the code a bit easier to read.
- Move Initialization to Declaration is also useful if you had conditional local initialization which has been eliminated.
#Availability
Available from the context menu or via shortcuts:
- when the edit cursor, or caret is on a local variable that is declared without an initialization.
#Tips
- Move Initialization to Declaration can be used to make Inline Temp and Replace Temp with Query refactorings available.
- You can use Move Declaration Near Reference before Move Initialization to Declaration. This may make the Move Initialization to Declaration refactoring available if the variable was initialized within a nested code block.
- Move Initialization to Declaration is the functional opposite of Split Initialization from Declaration.
#Example
int a;
│a = 15;
Dim │a As Integer
a = 15
Result:
int a = 15;
Dim a As Integer = 15
#Animation
See Also