All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S1656.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

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:

  • The statement is redundant and should be removed
  • The re-assignment is a mistake, and another value or variable was intended for the assignment instead

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy