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: Replace with single assignment

Last modified: 08 April 2024

To set a value for a bool variable depending on a certain condition, you can use a single statement in which you join the condition checking and the assignment.

Below, the result of the Contains method determines whether bool a will be true or false. Contains returns bool, so you can assign the result of the method directly to a. ReSharper helps you eliminate the If statement and assign the result of Contains to a.