Total .NET Analyzer Rule Documentation  

StatementNeverExecuted Rule

The branch is never taken. Consider removing statements that are never executed.

Remarks

There is no condition in which the branch can be taken, and therefore the statement can never be executed. For instance, the following example shows a branch that can never be taken:


' VB
Dim myInt As Integer = 1
If myInt < 0 Then
myInt = -myInt
End If

// C#
int myInt = 1;
if(myInt < 0)
{
myInt = -myInt;
}


Although having code that is not executed does not affect functionality, it can use excess system resources and negatively impact code performance. Additionally, having unused statements can clutter code, making it difficult to read and maintain (and in some cases, unintelligible).

More importantly, code that is never executed could indicate deeper logic issues in your application.

Resolution

You should review all statements that cannot be executed to ensure that they do not represent logic errors. If the code is unnecessary, you should consider removing it to keep your application running optimally and to keep your code readable and manageable.

See Also