Back to Devexpress

Discard Variable

coderushforroslyn-401186-refactoring-assistance-discard-variable.md

latest862 B
Original Source

Discard Variable

  • Aug 19, 2021

Purpose

Replaces a variable that is never used in code with discard.

Availability

Available when the cursor is in an unused variable. This variable can be replaced with discard.

How to Use

  1. Place the caret in an unused variable. For example, in the “assignment” variable.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Unused Local -> Discard ‘xxx’ from the menu.

After execution, the Refactoring replaces the unused local variable with discard.

csharp
public static class DiscardVariable {
    public static bool HasAssignment(this SimpleNameSyntax identifier) {
        return identifier.HasAssignment(out _);
    }
}