Code inspection: Expression is always 'null'
Last modified: 27 August 2024tip
This inspection reports expressions that are known to always evaluate to null
based on value and nullability analysis.
ReSharper suggests replacing such expressions with the explicit null
. Firstly, it will improve the readability of the code, but it can also improve performance when the expression requires some calculations or if the code is a part of a heavily used API.
The example below demonstrates the simplest case where it is obvious that input
will be always null
inside the if (input == null)
condition. However, in real-life situations, the always-null expression can be separated from the related check by multiple lines of code and would not be that easy to spot.