Back to Devexpress

Remove Variable with its Initializer

coderushforroslyn-401183-refactoring-assistance-remove-variable-with-its-initializer.md

latest1.3 KB
Original Source

Remove Variable with its Initializer

  • Aug 19, 2021

Purpose

Removes an unused variable with its initializer from code.

Availability

Available when the cursor is in an initialized variable. This variable is never used in code and can be deleted.

How to Use

  1. Place the caret in an initialized variable. For example, in the “statementsList” variable.

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

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

After execution, the Refactoring removes the unused variable with its initializer.

csharp
class RemoveVariable {
    private BlockSyntax GetGetterBody(IMemberDescriptor field) {
        return SyntaxFactory.Block(new StatementSyntax[] { FieldToReturnStatement(field) });
    }
}
vb
Class RemoveVariable
    Private Function GetGetterBody(ByVal field As IMemberDescriptor) As BlockSyntax
        Return SyntaxFactory.Block(New StatementSyntax() {FieldToReturnStatement(field)})
    End Function
End Class

See Also

Remove Variable

Remove Discard Variable