Share via


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 Creating Console Applications.

  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 Creating Console Applications.

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

    Note

    You can invoke rename refactoring by using smart tags only 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. Add the following code after the Program class. For more information, see Creating Console Applications.

class ProtoClassA
{
    // Declare 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

Concepts

Refactoring

Building Console Applications

Reference

Rename

Change History

Date

History

Reason

March 2009

Clarified the smart tags procedure and the example.

Information enhancement.