S1656 — Variables should not be self-assigned

Language
C#
Type
Bug
Severity
Major

Why is this an issue?

Re-assigning a variable to itself is a defect as it has no actual effect and indicates meaning to do something else. It usually means that:

Code examples

Noncompliant code example


public class Choice {
    private bool selected;

    public void MakeChoice(bool selected)
    {
        selected = selected; // Noncompliant
    }
}

Compliant solution


public class Choice {
    private bool selected;

    public void MakeChoice(bool selected)
    {
        this.selected = selected; // Compliant
    }
}

Resources

Documentation

↑ Back to top