Home > Enterprise >  using and operator for constant order type values
using and operator for constant order type values

Time:09-17

Experts ,I've one issue where I want to combine two constant values while checking if statement. One order type with IF is working but I need to check two order types.Both have same products list.

Existing code-working for one order type

 if (SF_OrderType_textBox.Text == "HHC Medicaid");
        {
            SF_Addl_Product_textBox.Text = PopulateNextField(Addl_Products_List, SF_Addl_Product_textBox.Text);
        }

want to achieve below with two order types-But not working

 if (SF_OrderType_textBox.Text == "HHC Medicaid"&"HHC Rentals");
        {
            SF_Addl_Product_textBox.Text = PopulateNextField(Addl_Products_List, SF_Addl_Product_textBox.Text);
        }

this AND(&) operator is not working. Can you please advise whats the correct syntax for this?

Thanks

CodePudding user response:

If you want to perform logic AND & with two strings then the condition will always be false, yes?

(a == "a" & a == "b")

False

Maybe you are looking for logic OR |

(a == "a" | a == "b")

True

Also look at short-circuiting the OR ||

(a == "a" || a == "b")

True, but only evaluates first statement because OR condition is met

Apply it to your code, simplys

if (SF_OrderType_textBox.Text == "HHC Medicaid" || SF_OrderType_textBox.Text == "HHC Rentals");

If you could have a list of those HHC types you could put them in an array to make your code more extensible.

var hhcTypes = new string[] { "HHC Medicaid", "HHC Rentals" };
if (hhcTypes.Contains(SF_OrderType_textBox.Text))
  • Related