is it possible in some way to compare multiple variables to one constant in a if statement? It would be very helpful if instead of
if ( col.Name != "Organization" && col.Name != "Contacts" && col.Name != "Orders" ) { }
I could just say
if ( col.Name != "Organization" || "Contacts" || "Orders" ) { }
And I know I could use a list but in some instances I dont want to... Thanks!
If you're just looking for a shortcut, you probably won't get much. ChaosPandion mentioned the switch statement, and here's something using an array.
if (new string[] { "Bar", "Baz", "Blah" }.Contains(foo))
{
// do something
}
The switch statement is about as good as you'll get.
switch (col.Name)
{
case "Organization":
case "Contacts":
case "Orders":
break;
default:
break;
}
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