Is there a way of shortening if(a=="bcd" || a=="efg")
?
Because the conditions are both on a
It would be nice to write something like if(a=="bcd"||"efg")
and contract the statement. I know I could write something custom to handle it, but was wondering if there is anything built into C# that would accomplish it?
When you combine each one of them with an IF statement, they read like this: AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False) OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False) NOT – =IF(NOT(Something is True), Value if True, Value if False)
Java else if StatementWe can use multiple if and else statements as long as a condition is not met. Note: we can have multiple else if statements but we always terminate with an else statement.
With C# 9's patterns, you can write:
if (a is "bcd" or "efg")
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With