← back to index

S1940 — Boolean checks should not be inverted

Language: C#  |  Type: CODE_SMELL  |  Severity: Minor

Tags: pitfall

Why is this an issue?

It is needlessly complex to invert the result of a boolean comparison. The opposite comparison should be made instead.

Noncompliant code example

if ( !(a == 2)) { ...}  // Noncompliant
bool b = !(i < 10);  // Noncompliant

Compliant solution

if (a != 2) { ...}
bool b = (i >= 10);