Total .NET Analyzer Rule Documentation  

UnreachableCode Rule

The code is unreachable.

Remarks

There is code in the application that is unreachable, and can never be executed. For example, if there is code after a return statement, it will not be executed:


' VB
Function UnreachableCode() As Integer
Return 0
Console.WriteLine("This line is unreachable")
End Function

// C#
public static int UnreachableCode()
{
return 0;
Console.WriteLine("This code is unreachable")
}


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

More importantly, unreachable code could indicate deeper logic issues in your application. For instance, the Assignment could represent important functionality that has not been implemented.

Resolution

You should review all unreachable code to ensure that it does not represent important functionality that should be implemented. 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