Skip to main content

Rename

  • 2 minutes to read

Purpose

Renames a symbol and updates all references to it. This refactoring runs the Visual Studio’s Rename quick action.

Availability

Available when the caret is in a symbol declaration.

Usage

  1. Place the caret in a code symbol (a field, local variable, method, namespace, property, or a type).

    Note

    The blinking cursor shows the caret’s position at which the Refactoring is available.

    static void Main(string[] args) {
        Console.Write("Mass (kg): ");
        double m = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine($"F = {m * 9.807} N");
        Console.ReadLine();
    }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Rename from the menu and press Enter.

    rename-refactoring

  4. In the code editor, type the new symbol name. Press Enter or click Apply in the Rename hint to save the change.

    apply-rename

After execution, this refactoring changes the symbol name and updates all references to it.

static void Main(string[] args) {
    Console.Write("Mass (kg): ");
    double mass = Convert.ToDouble(Console.ReadLine());
    Console.WriteLine($"F = {mass * 9.807} N");
    Console.ReadLine();
}