Back to Devexpress

CRR0004 - Ternary expression has identical branches

coderushforroslyn-118093-static-code-analysis-analyzers-library-crr0004-ternary-expression-has-identical-branches.md

latest797 B
Original Source

CRR0004 - Ternary expression has identical branches

  • Feb 28, 2025

This analyzer detects ternary expressions that always return the same value. Check the following example.

csharp
var result = condition ? a + b : b + a; // CRR0004
vb
Dim result = If(condition, (a + b), (b + a))

These expressions are redundant because the condition value never changes the resulting value. You can modify one of the branches or change the ternary expression to a simple assignment.

See Also

Suppress Analyzers