我是编程的初学者,我正在尝试这个简单的程序来获取用户名并对其进行排序等等。
class Program
{
static void Main(string[] args)
{
int number;
dynamic y;
string[] answer = new string[10];
cases:
Console.WriteLine("Enter the options given below 1.Add students\n 2.View all details\n 3.Sorting\n 4.Exit\n");
int input = Convert.ToInt16(Console.ReadLine());
switch (input)
{
case 1:
Console.WriteLine("Enter the Number of Students to be added to the List");
number = Convert.ToInt16(Console.ReadLine());
for (int i = 0; i < number; i++)
{
answer[i] = Console.ReadLine();
}
case 2:
foreach (var item in answer)
{
Console.WriteLine(item.ToString());
}
break;
case 3:
Array.Sort(answer);
foreach (var item in answer)
{
Console.WriteLine(item.ToString());
}
break;
case 4:
Console.WriteLine("Are you sure you want to exit");
Console.WriteLine("1 for Yes and N for No");
y = (char)Console.Read();
if ((y == 1))
{
goto cases;
}
else
{
goto thankyou;
}
thankyou:
Console.WriteLine("thank you");
break;
}
Console.WriteLine("Are you sure you want to exit");
Console.WriteLine("Y for Yes and 1 for No");
y = (char)Console.Read();
if ((y == 1))
{
goto cases;
}
else
{
goto thankyou;
}
}
}
我的问题是,每次操作后我都会询问是否应该继续。我已经添加了语句,但是当按下 No 时,它会显示我声明go-to
的变量的异常。input