Skip to main content

CRR0044 - Unused local variable

This analyzer detects variables that are never used in your code and can be deleted.

class RemoveVariable {
    BlockSyntax GetGetterBody(IMemberDescriptor field) {
        var statementsList = new List<StatementSyntax>();
        return SyntaxFactory.Block(new StatementSyntax[] { FieldToReturnStatement(field) });
    }
}

To fix the issue, remove the unused variable:

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

Call one of the Remove Variable, Remove Variable with its Initializer, and Remove Discard Variable refactorings to remove the unused variable from your code. To do it in different places at once, use the Code Cleanup feature with the Remove unused variables rule enabled.