4
I often fall into the following situation :
For example in c#:
string variavel= "x";
boolean b = (variavel == "a" || variavel == "d" ||.....|| variavel== "y");
Is there any way to simplify something like b =("a" || "b" || .... ||" y")?
In addition to being annoying I think it will greatly improve readability if there is something similar. Switch case does not help much .
Yes use
in_array()
;)– rray
You need to choose a language, the way to solve the problem changes from one to another.
– rray
Thanks rray , the intention to know how you solve this situation on a daily basis. The solution of the array is great ! I don’t understand why languages in general don’t come with something intuitive like an operator |= "a'',"b","c"
– John Diego
In C#, using LINQ, you can do the following:
bool b = new string[] {"a", "b", ...}.Any(s => s == variavel);
– Omni