Let’s say you have a condition like that:
if ((myString.Contains("Value1") && (myString.Contains("Value2")) && (myString.Contains("Value3"))) { ... }
Basically, you want to check if all of your values are contained in the string . Fortunately (with the help of LINQ), this can by translated almost literally into C#:
var values = new String[] {"Value1", "Value2", "Value3"}; if (values.All(v => myString.Contains(v))) { ... }
Similarly, if you want to check if any value is contained in the string, you’d substitute All
by Any
.
if ((myString.Contains("Value1") || (myString.Contains("Value2")) || (myString.Contains("Value3"))) { ... } //You can translate it to this: if (values.Any(v => myString.Contains(v))) { ... }