C#

C#

By DeepSource

Unreachable code detectedCS-W1016

Bug risk

Statements placed after the return statement are not executed and is considered as "dead" code. Either adding the return statement was a mistake or that the code placed after the return statement wasn't supposed to be there in the first place. Either way, it is recommended that you rectify this immediately.

Examples

Bad Practice

foreach (var item in items)
{
    // ...
    return;

    // ...
}

Recommended

foreach (var item in items)
{
    // ...
    if (!ShouldPick(item))
        return;

    // ...
}