Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C#
Refactoring
Rename
 How to: Rename Identifiers

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual C# Application Development 
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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker