Simplify if statement with multiple or's involving same variable?
c#
Solution
You can use LINQ but it don't think it's very useful if you have only four conditions:
if (new[] {a,b,c,d}.Any(current => current > x))
and
if (new[] {a,b,c,d}.Any(current => x.Contains(current)))
Problem
Let's say I have an if statement like this: ``` if (a > x || b > x || c > x || d > x) {} ``` Assume it always involves the same repeated variable (x in this case) and the same operation, but the operation isn't the same between all uses. For example, another if statement may use: ``` if (x.Contains(a) || x.Contains(b) || x.Contains(c) || x.Contains(d)) {} ``` Is there a way to simplify these if statements in C# so we don't end up typing the same thing over and over? I'd prefer not making an extra function to call for this instance.