Skip to main content

CRR0045 - Local variable can be replaced with discard

This analyzer detects unused or assigned variables which can be replaced with a discard.

public static class ReplaceWithDiscard {
    public static bool HasAssignment(this SimpleNameSyntax identifier) {
        SyntaxNode assignment;
        return identifier.HasAssignment(out assignment);
    }
}

To fix the issue, replace the local variable with discard:

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

Call the Discard Variable refactoring to replace unused or assigned variables with a discard. To do it in different places at once, use the Code Cleanup feature with the Replace unused variables with discard code cleanup rule enabled.