Introduce Constant (local)
In This Article
Declares a new constant in the member, initialized to the value of the string or number under the caret.
#Availability
Available from the context menu or via shortcuts:
- when the edit cursor, or caret is on a number or string in the code.
#Notes
- This refactoring is equivalent to Introduce Constant. The only difference is that a constant is created within the current method, instead of getting class-wide scope.
#Example
public int AddValue(int ValueA)
{
return ValueA + │25;
}
Public Function AddValue(ByVal ValueA As Integer) As Integer
Return ValueA + │25
End Function
Result:
public int AddValue(int ValueA)
{
const int MyConst = 25;
return ValueA + MyConst;
}
Public Function AddValue(ByVal ValueA As Integer) As Integer
Const MyConst As Integer = 25
Return ValueA + MyConst
End Function