Using If "II" to check for multiple possibilities of the same query

c#, if-statement

Solution

Create a collection that holds the different possibilities:

if(new[] {"string1", "string2", "string3" }.Contains(sCheck)) { }

Problem

This is normally something I can find online pretty easily but I think I'm having trouble wording it so I apologize if this is a duplicate question. I'm looking for a more concise way to do an IF/OR check for the same query. For example: ``` if (sCheck == "string1" || sCheck == "string2" || sCheck == "string3") { MessageBox.Show(sCheck + " is one of the three possible strings."); } ``` I'm looking for a cleaner more concise way to do the same If/Or. I was hoping something like these would work but of course they don't: ``` if (sCheck == "string1" || "string2" || "string3") { } if (sCheck == ("string1" || "string2" || "string3")) { } ```

Original source

Related problems