Back to Devexpress

CRR0001 - Redundant sub-expressions in a binary operation

coderushforroslyn-118082-static-code-analysis-analyzers-library-crr0001-redundant-sub-expressions-in-a-binary-operation.md

latest976 B
Original Source

CRR0001 - Redundant sub-expressions in a binary operation

  • Feb 28, 2025

This analyzer detects identical sub-expressions in the binary operation. Such sub-expressions are redundant and the expression can be simplified.

csharp
if ((a > 10) && (a > 10)){ // CRR0001
    bool c = b == "foo" || b == "foo"; // CRR0001
}
vb
If (a > 10) AndAlso (a > 10) Then ' CRR0001
    Dim c As Boolean = b = "foo" OrElse b = "foo" ' CRR0001
End If

Use the Simplify Expression refactoring to fix this code.

csharp
if (a > 10){
    bool c = b == "foo";
}
vb
If a > 10 Then
    Dim c As Boolean = b = "foo"
End If

See Also

Suppress Analyzers