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;
}
}
我有4个功能可以帮助我做以下事情 加 编辑 搜索 退出
我想使用switch case转到该功能。可能吗? 它要求对象引用,然后是标签。
答案 0 :(得分:2)
为什么不在没有goto的情况下调用方法?对我来说,这不是使用goto的正确方法,cfr MSDN Reference
这对我来说应该没问题:
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;
}
}
答案 1 :(得分:0)
删除goto
。这些仅在您使用标签时使用。只需致电fun.Add()
或fun.Edit()
。等等