Back to Devexpress

CRR0005 - Expression value is always the same

coderushforroslyn-118098-static-code-analysis-analyzers-library-crr0005-expression-value-is-always-the-same.md

latest1.1 KB
Original Source

CRR0005 - Expression value is always the same

  • Feb 28, 2025

This analyzer detects invariant conditions. Such conditions evaluate to the same value regardless of variables they include. For instance, consider the following example.

csharp
if (condition && !condition) { // CRR0005
    // ...
}
vb
If condition AndAlso (Not condition) Then ' CRR0005
    ' ...
End If

To make it clear, look at the truth table of this expression.

condition!conditioncondition && !condition
TrueFalseFalse
FalseTrueFalse

As you see, the last column has the same value in each row, which means variables in this expression do not affect the result. You need to modify such expressions or change your code to avoid the condition.

In the example above, the code inside the condition will never be executed, so this block can be completely removed.

See Also

Suppress Analyzers