back: Console.Write("The first number= ");
int x = int.Parse(Console.ReadLine());
if (x== string ) { goto back;} // here my proplem
我如何建模:意思是如果x输入字符串goto
返回
使用循环与 int。TryParse检查值是否为number,当number正确输入时,将从循环中断开。
int x;
while(true)
{
Console.Write("The first number= ");
bool success = int.TryParse(Console.ReadLine(), out x);
if (success)
break;
}
或者如果您想使用goto
int x;
back:
Console.Write("The first number= ");
bool success = int.TryParse(Console.ReadLine(), out x);
if (!success)
goto back;