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: Convert 'if' into '||'

Last modified: 08 April 2024

An If statement can be rewritten using the conditional OR operator, provided that it’s a bool value that you modify depending on the result of the If statement.

Below, the Contains method returns bool, so you can assign the result of the method directly to a bool variable a. ReSharper provides a quick-fix on If, which replaces If with the conditional OR operator to simplify the code: