-5

Is it possible to return result from multiple switch statement?

For example i would like to use employee.DepartmentID and employee.StatusID for my case. But how do i include employee.StatusID in this statement? Using and/or operators?

                switch (employee.DepartmentID)
            {
                case 1:
                    EMAIL = "abc@gmail.com";
                    break;
                case 2:
                    EMAIL = "abcd@gmail.com";
                    break;
            }
thatthing
  • 676
  • 3
  • 15
  • 39
  • 1
    If you are looking for `switch (employee.DepartmentID || employee.StatusID)` then it is not possible. – Habib Sep 16 '14 at 20:52
  • 1
    that doesn't sound like a viable solution. you can concat the strings `switch(employee.DepartmentID + employee.StatusID` – DidIReallyWriteThat Sep 16 '14 at 20:52
  • 2
    So if the department is `1` and the status is `2`, what should happen? – Servy Sep 16 '14 at 20:53
  • 2
    Can you give an example of what your ideal switch statement would look like? And (building on what @Servy asked) why would departmentID = 1 and Status = 2 be different than departmentID = 2 and status = 2 or departmentID = 1 and status = 1. Basically, what is the benefit you are looking for from the multiple conditions. – Chuck Buford Sep 16 '14 at 20:53
  • For example if the departmentID is 1 and StatusID is 1 then EMAIL will be abc@gmail.com – thatthing Sep 16 '14 at 20:55
  • 1
    So, you have a separate email for each department based on status? Ok. That we can work with. – Chuck Buford Sep 16 '14 at 20:55
  • 1
    sounds like you should use an If Condition. – MethodMan Sep 16 '14 at 20:57

1 Answers1

2

What you really need is this.

Use the Switch to determine which department is involved

  Switch (DepartmentID)
  {

     case  1:
         Email = classHR.GetEmailAddress(Status);
         break;
     case  2: 
         Email = classMarketing.GetEmailAddress(Status);
         break;
   }

Use Static Classes for the different departments (using an interface preferably).

This will give you a better run down than what you are thinking of here.

Chuck Buford
  • 321
  • 1
  • 9