This documentation is archived and is not being maintained.

How to: Promote Local Variable to Parameter

Visual Studio 2008

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 How to: Create a C# Console Application.

  2. Place the pointer next to i at its definition in MethodB.

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

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

    You can also right-click the pointer, 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, and the call ProtoA.MethodB will now pass zero as a value.

To set up this example, create a console application named PromoteLocal, and then add the following code after the Program class in the PromoteLocal namespace. For more information, see How to: Create a C# Console Application.

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

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