简体   繁体   中英

Switch Statement C#

Can someone please tell me why my switch statement is not working? In my program I have a text box with the choices of 'Billing', 'Tech Support', 'Retention', 'Customer Service'. My switch statement is saying if that text box is = xxx then show a form I build and hide everything else.

Currently only the billing and other option works?!

<

private void cbDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            string reason = cbDept.Text;

            switch (reason)
            {
                case "Billing":
                    gbBilling.Show();
                    gbTechSupport.Hide();
                    gbCS.Hide();
                    gbRetention.Hide();
                    lbOtherReason.Hide();
                    txtOther.Hide();
                    break;
                case "Tech Support":
                    gbTechSupport.Show();
                    gbBilling.Hide();
                    gbCS.Hide();
                    gbRetention.Hide();
                    lbOtherReason.Hide();
                    txtOther.Hide();
                    break;
                case "Retention":
                    gbRetention.Show();
                    gbBilling.Hide();
                    gbTechSupport.Hide();
                    gbCS.Hide();
                    lbOtherReason.Hide();
                    txtOther.Hide();
                    break;
                case "Customer Service":
                    gbCS.Show();
                    gbBilling.Hide();
                    gbTechSupport.Hide();
                    gbRetention.Hide();
                    lbOtherReason.Hide();
                    txtOther.Hide();
                    break;
                case "Other":
                    txtOther.Show();
                    lbOtherReason.Show();
                    gbCS.Hide();
                    gbBilling.Hide();
                    gbTechSupport.Hide();
                    gbRetention.Hide();
                    break;
                default:
                    gbCS.Hide();
                    gbBilling.Hide();
                    gbTechSupport.Hide();
                    gbRetention.Hide();
                    break;
            }

        }

>

It seems to me that there is some misspelling in the other options. Check the values of reason before reaching the switch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM