The requested page is not available for the requested platform. You are viewing the content for Default platform.
All docs
V19.2
19.2
19.1
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Remove Variable

Purpose

Removes a variable that is never used in code.

Availability

Available when the cursor is in an unused variable.

How to Use

  1. Place the caret in an unused variable.
Note

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

public class RemoveUnusedVariable {
    string GetMethodName(ISymbol symbol) {
        if (symbol is IMethodSymbol methodSymbol) {
            return symbol.Name;
        }
        return null;
    }
}
  1. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.

RemoveVariable

  1. Select Unused Local -> Remove 'xxx' Variable from the menu.

After execution, the Refactoring removes the unused variable.

public class RemoveUnusedVariable {
    string GetMethodName(ISymbol symbol) {
        if (symbol is IMethodSymbol) {
            return symbol.Name;
        }
        return null;
    }
}
See Also