ReSharper 2017.2 Help

Code Inspection: Convert 'if' to '||'

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:

Suboptimal codeAfter the quick-fix
private static void TestMethod(string s, bool b) { bool a = b; if (!s.Contains(".")) { a = true; } Console.WriteLine(a); }
private static void TestMethod(string s, bool b) { bool a = b || !s.Contains("."); Console.WriteLine(a); }
Last modified: 11 December 2017

See Also