Back to Devexpress

Remove Variable

coderushforroslyn-401182-refactoring-assistance-remove-variable.md

latest1.2 KB
Original Source

Remove Variable

  • Aug 19, 2021

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. For example, in the “methodSymbol” variable.

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

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

After execution, the Refactoring removes the unused variable.

csharp
public class RemoveUnusedVariable {
    string GetMethodName(ISymbol symbol) {
        if (symbol is IMethodSymbol) {
            return symbol.Name;
        }
        return null;
    }
}
vb
Public Class RemoveVariable
    Private Function FormatString(ByVal temperature As Decimal) As String
        Dim s As String = String.Format("the temperature is {0}", temperature)
        Return s
    End Function
End Class

See Also

Remove Variable with its Initializer

Remove Discard Variable