The requested page is not available for the requested platform. You are viewing the content for Default platform.

Remove Variable with its Initializer

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.
Note

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

class RemoveVariable {
    private BlockSyntax GetGetterBody(IMemberDescriptor field) {
        var statementsList = new List<StatementSyntax>();
        return SyntaxFactory.Block(new StatementSyntax[] { FieldToReturnStatement(field) });
    }
}
  1. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.

RemoveVariable

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

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

class RemoveVariable {
    private BlockSyntax GetGetterBody(IMemberDescriptor field) {
        return SyntaxFactory.Block(new StatementSyntax[] { FieldToReturnStatement(field) });
    }
}
See Also