I'm looking for short coding style for the if condition containing multiple expression.
Let's suppose, I want to add if condition in a string variable name str.
Here is my if condition.
if(str == "a" || str == "b" || str == "c" || str == "d")
I want to make this if condition short something like that.
if(str == "a" || "b" || "c" || "d")
or
if (str in {"a", "b", "c", "d"})
I don't have to put str == again and again.
I know, I can do this using multiple ways:
- Using switch statement
- Making array/list of string and use LINQ or Contains to check.
I want to do some something similar to if(str == "a" || "b" || "c" || "d") or if (str in {"a", "b", "c", "d"})
Thank you for your help!