Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Access multiple Variables from within a switch statement C#

Good day, I'm after a bit of help.

I'm currently trying to create a program that will access an EmailHandler. that I'm writing.

within said program, there are multiple "Addon" applications that have access to the same handler but have a different subject and body to be sent.

I've currently got it in a Switch statement like this.

           switch (mainMenu.SelectedApplication)
            {
                case "Application1":
                    {
                        LogHandler.Log(LogTarget.File, "Selected Application: Application 1 Queued");
                        string SUBJECT = "blah blah";

                        string BODY = "blah blah";
                    }
                    break;
                case "Application2":
                    {
                        LogHandler.Log(LogTarget.File, "Selected Application: Application 2 Queued");
                        string SUBJECT = "blah blah";

                        string BODY = "blah blah";
                    }
                    break;
                case "Application3":
                    {
                        LogHandler.Log(LogTarget.File, "Selected Application: Application 3 Queued");

                        string SUBJECT = "blah blah";

                        string BODY = "blah blah";
                    }
                    break;
            }

I've then got the Names of the applications coming through as SelectedApplication = "Application1"; etc..

all that works fine. when I get the LogHandler to spout out the information within the selected Case

however when I try to grab the data from the selected case

I'm getting > The name 'SUBJECT' does not exist in the current context

when I try

MailMessage message = new MailMessage();

message.Subject = SUBJECT;
message.Body = BODY;

etc

I'm still fairly new to C# so forgive me if it is an obvious answer.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

move SUBJECT and BODY out of switch

    string SUBJECT = string.Empty;
    string BODY = string.Empty;

    switch (mainMenu.SelectedApplication)
    {
        case "Application1":

          LogHandler.Log(LogTarget.File, "Selected Application: Application 1 Queued");

                 SUBJECT = "blah blah";

                 BODY = "blah blah";
            
       ....
    }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!