Export (0) Print
Expand All

How to: Promote Local Variable to Parameter 

Use this procedure to perform the Promote Local Variable to Parameter refactoring operation. For more information, see Promote Local Variable to Parameter.

To promote a local variable to parameter

  1. Create a console application, and set it up as described in the following example. For more information, see Console Application Template.

  2. Place the cursor on i in MethodB.

  3. From the Refactor menu, select Promote Local Variable to Parameter.

    You can also type the keyboard shortcut CTRL+R, CTRL+P to complete the refactoring operation.

    You can also right-click the cursor, point to Refactor on the context menu, and then click Promote Local Variable to Parameter to complete the refactoring operation.

The MethodB should now have a parameter int i, while the call ProtoA.MethodB will now pass 0 as a value.

Example

To set up this example, create a console application named PromoteLocal, and then replace Class1 with the following code. For more information, see Console Application Template.

    class ProtoA
    {
        public static void MethodB()
        {
            // Invoke on 'i'
            int i = 0;
        }
    }

    class ProtoC
    {
        void MethodD()
        {
            ProtoA.MethodB();
        }
    }

See Also

Concepts

Refactoring

Community Additions

ADD
Show:
© 2014 Microsoft