
VS 2005+Visual Studio Promote Local Variable to Parameter
Sometimes a local variable within a method must be converted to a parameter of the method as the software develops. In such cases, Visual Studio provides a command that allows the variable to be promoted without breaking references elsewhere in the code.
Promote Local Variable to Parameter Command
As your software changes, you can often find that a local variable within a method would be more useful if it were a parameter. To convert the variable, you must remove its declaration from the body of the method and add it as a parameter. All references to the method elsewhere in the code must then be updated to pass a value to the new parameter.
Visual Studio's Promote Local Variable to Parameter command performs this conversion automatically, ensuring that the code continues to compile after the variable's promotion. The variable that is selected must be declared and assigned a constant value. If so, it is removed from the method's code block and inserted as the last parameter of the method. All calls to the method are modified so that the original constant value is passed to the new parameter.
To access the command, simply right-click the variable that is to be modified. From the context-sensitive menu that appears, select "Refactor", then choose Promote Local Variable to Parameter.

23 January 2009