The requested page is not available for the requested platform. You are viewing the content for Default platform.

Inline Temp

  • 2 min to read

Purpose

This Refactoring replaces all references to a local variable with its initial value.

You may find a variable in your code whose value does not change and the meaning is trivial. If this variable is not commonly used, you can eliminate it by executing the Inline Temp Refactoring.

Availability

Available when the cursor is on a local variable declaration or reference assuming the variable does not change.

Usage

  1. Place the caret on a local variable whose value does not change.

    Note

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

    float CalculateDiscount(float price) {
        int percentage = GetCurrentDiscount();
        float fraction = (float)percentage / 100;
        return price - fraction * price;
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Inline Temp from the menu.

After execution, the Refactoring replaces the variable references with its initial value and removes the initialization.

float CalculateDiscount(float price) {
    int percentage = GetCurrentDiscount();
    return price - (float)percentage / 100 * price;
}
See Also