just to throw some code out there
string answer = "hotel"
if (answer == "house"|| answer == "hotel" || answer =="appartment")
{
DoSomething()
}
I was wondering if there was some way to shorten it to
string answer = "hotel"
if (answer == "house"|| "hotel" || "appartment")
{
DoSomething()
}
I am aware of the switch statement
switch (answer)
{
case "house":
case "hotel":
case "appartment": DoSomething();
break;
default :DoNothing();
}
I am just wondering if there is some syntax sugar like what I described above.
It is possible to use some syntactic sugar for this:
Note that this will create a new array on the fly, so will potentially be more expensive than just the
Booleanchecks.