ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Heuristically unreachable code

Last modified: 30 September 2024

Among other things, ReSharper analyzes values and nullability and integer arithmetic, and uses the results of these analyses to identify code that never executes.

In the example below, this inspection reports Console.WriteLine("Error"); as unreachable, because the program can only enter the foreach loop if the list is not null. Therefore, the condition list == null will always be false inside this loop, and as a result, any code within this condition will never execute.