Skip to main content

CRR0012 - Logical OR expression has opposite operands

  • 2 minutes to read

This analyzer detects expressions that contain logically opposite parts separated by the ‘||’ (OR) statement.

if (str == null || str != null && str == ""){ // CRR0012
    // ...
}

Such expressions can be simplified. Refer to the following chain of transformations.

str == null || (str != null && str == "");
(str == null || str != null) && (str == null || str == ""); // Distributive property
true && (str == null || str == ""); // (a || !a) == true
str == null || str == ""; // true && b == b

Thus, the str != null (str IsNot Nothing) expression is redundant and can be omitted.

if (str == null || str == ""){
    // ...
}