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: Expression is always 'true' or always 'false'

Last modified: 30 September 2024

This inspection is fairly obvious: ReSharper analyzes values and nullability, integer arithmetic, and so on, and suggests eliminating expressions that are always true or always false based on its analysis results.

The only problem with this inspection is that sometimes it's not obvious how ReSharper has come to this conclusion. Because of this, you may be unwilling to accept suggestions to replace expressions with explicit true or false, or to remove redundant checks in if statements. Below are some StackOverflow questions that illustrate this problem: