Skip to main content
A newer version of this page is available. .

Remove Discard Variable

Removes a discard variable that serves no purpose in code.

Availability

Available when the cursor is in a discard variable.

How to Use

  1. Place the caret in a discard variable.
NOTE

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

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

RemoveVariable

  1. Select Remove Discard Variable from the menu.

After execution, the Refactoring removes the discard variable.

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