C#

C#

Made by DeepSource

Empty else statement is redundant CS-R1129

Anti-pattern
Major
Autofix

The else clause is used to define what happens in case the if condition evaluates to false. Any empty else clause is redundant and can be dropped safely. Either add a user comment inside explaining why the said clause is empty or drop it altogether.

Bad Practice

if (condition)
{
    Do();
}
else
{
}

Recommended

// Alternate 1: Add a user comment
if (condition)
{
    Do();
}
// Let this be empty
else
{
}

// Alternate 2: Drop the `else` clause
if (condition)
{
    Do();
}