Skip to content

Gendarme.Rules.Correctness.ReviewUseOfModuloOneOnIntegersRule(git)

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

ReviewUseOfModuloOneOnIntegersRule

Assembly: Gendarme.Rules.Correctness
Version: git

Description

This rule checks for a modulo one (1) operation on an integral type. This is most likely a typo since the result is always 0. This usually happen when someone confuses a bitwise operation with a remainder.

Examples

Bad example:

public bool IsOdd (int i)
{
    return ((i % 1) == 1);
}

Good example:

public bool IsOdd (int i)
{
    return ((i % 2) != 0); // or ((x & 1) == 1)
}

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