Export (0) Print
Expand All

How to: Rename Identifiers 

The following procedure describes how to rename an identifier in your code. Use this procedure to perform the Rename refactoring operation.

To rename an identifier

  1. Create a console application as described in the following Example section.

    For more information, see Console Application.

  2. Place the cursor on MethodB, either in the method declaration or the method call.

  3. From the Refactor menu, select Rename. The Rename Dialog Box appears.

    You can also type the keyboard shortcut F2 to display the Rename Dialog Box.

    You can also right-click the cursor, point to Refactor on the context menu, and then click Rename to display the Rename Dialog Box.

  4. In the New Name field, type MethodC.

  5. Select the Search in Comments check box.

  6. Click OK.

  7. In the Preview Changes dialog box, click Apply.

To rename an identifier using smart tags

  1. Create a console application as described in the following Example section.

    For more information, see Console Application.

  2. In the declaration for MethodB, type or backspace over the method identifier. A smart tag prompt will appear below this identifier.

    NoteNote

    You can only invoke rename refactoring using smart tags at the declaration of an identifier.

  3. Type the keyboard shortcut SHIFT+ALT+F10, and then press the DOWN ARROW to display the smart tag menu.

    -or-

    Move the mouse pointer over the smart tag prompt, to display the smart tag. Then move the mouse pointer over the smart tag and click the down arrow to display the smart tag menu.

  4. Select the Rename '<identifer1>' to '<identifier2>' menu item, to invoke rename refactoring without a preview of the changes to your code. All references to <identifer1> will automatically be updated to <identifier2>.

    -or-

    Select the Rename with preview menu item, to invoke rename refactoring with a preview of the changes to your code. The Preview Changes dialog box will appear.

Example

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

class ProtoClassA
    {
        // Invoke on 'MethodB'.
        public void MethodB(int i, bool b) { }
    }

    class ProtoClassC
    {
        void D()
        {
            ProtoClassA MyClassA = new ProtoClassA();

            // Invoke on 'MethodB'.
            MyClassA.MethodB(0, false);
        }
    }

See Also

Reference

Rename

Concepts

Refactoring

Community Additions

ADD
Show:
© 2014 Microsoft