C#

C#

Made by DeepSource

If-else chain has a duplicate condition CS-W1084

Bug risk
Critical
Autofix

One or more if statements in the if-else chain have duplicate conditions. It is likely that you meant to specify a different condition but ended up specifying a condition that is already present in the chain. Since a flawed condition can affect your application's logic, it is recommended that you address this issue.

Bad Practice

if (x % 2 == 0)
{
    // ...
}
else if (x % 3 == 0)
{
    // ...
}
else if (x % 2 == 0) // Duplicate condition
{
    // ...
}

Recommended

if (x % 2 == 0)
{
    // ...
}
else if (x % 3 == 0)
{
    // ...
}
else if (x % 5 == 0) // Fixed
{
    // ...
}