-1
     FunWithScheduling fun = new FunWithScheduling();
     Console.WriteLine("This Is Your Scheduler");
     Console.WriteLine("What Do You Wish To Do");
     Console.WriteLine("Enter 1 To Add, 2 To Edit, 3 To Search And 4 To Exit");
     int Choice = Convert.ToInt32(Console.ReadLine());
     switch (Choice)
     {
              case 1:
                  goto fun.Add();
                  break;
              case 2:
                  goto fun.Edit();
                  break;
              case 3:
                  goto fun.Search();
                  break;
              case 4:
                  goto fun.Exit();
                  break;
             Default:
                   Console.WriteLine("Enter a Valid Number");   
                   return;
      }
 }

I got 4 functions that would help me do the following Add Edit Search Exit

I want to use switch case to go to the function. Is it possible? It asked for an object reference and then a label.

Joanah Jocks
  • 51
  • 1
  • 1
  • 4

2 Answers2

2

Why don't you just call the method without the goto ? and for me it's not the proper way to use a goto, cfr MSDN Reference

This should be ok for me :

FunWithScheduling fun = new FunWithScheduling();
 Console.WriteLine("This Is Your Scheduler");
 Console.WriteLine("What Do You Wish To Do");
 Console.WriteLine("Enter 1 To Add, 2 To Edit, 3 To Search And 4 To Exit");
 int Choice = Convert.ToInt32(Console.ReadLine());
 switch (Choice)
 {
          case 1:
              fun.Add();
              break;
          case 2:
              fun.Edit();
              break;
          case 3:
              fun.Search();
              break;
          case 4:
              fun.Exit();
              break;
         Default:
               Console.WriteLine("Enter a Valid Number");   
               return;
  }

}

Emmanuel Istace
  • 1,209
  • 2
  • 14
  • 32
0

Remove the goto. Those are only used if you are using labels. Simply call fun.Add() or fun.Edit()., etc.

Inisheer
  • 20,376
  • 9
  • 50
  • 82