Skip to content

Gendarme.Rules.Correctness.ReviewDoubleAssignmentRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

ReviewDoubleAssignmentRule

Assembly: Gendarme.Rules.Correctness
Version: git

Description

This rule checks for variables or fields that are assigned multiple times using the same value. This won't change the value of the variable (or fields) but should be reviewed since it could be a typo that hides a real issue in the code.

Examples

Bad example:

public class Bad {
    private int x, y;
    public Bad (int value)
    {
        // x is assigned twice, but y is not assigned
        x = x = value;
    }
}

Good example:

public class Good {
    private int x, y;
    public Good (int value)
    {
        // x = y = value; was the original meaning but since it's confusing...
        x = value;
        y = value;
    }
}

Notes

  • This rule is available since Gendarme 2.0

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally