我正在研究这个代码示例:
class Program
{
static void Main(string[] args)
{
int x = 10;
int y = 10;
int generate=0;
string [,] myArrayTable = new string[x, y];
Console.WriteLine("Enter a seek number: ");
string cautat = Console.ReadLine();
for (int i = 0; i < x; i++)
{
for(int j = 0;j < y; j++)
{
myArrayTable[i, j] = (generate++).ToString();
}
}
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
if(cautat.Equals(myArrayTable[i,j]))
{
goto Found;
}
}
}
goto NotFound;
Found:
Console.WriteLine("Numarul a fost gasit");
NotFound:
Console.WriteLine("Numarul nu a fost gasit !");
Console.ReadKey();
}
}
我不明白为什么“未找到”语句被调用,并且如果我输入像 10 这样的搜索编号,则在控制台上打印相应的消息,在这种情况下 goto: Found 语句正在执行,所以 goto: NotFound 语句将永远不会被调用,但是它的相应消息仍然打印在控制台上,我不明白为什么在这种情况下程序永远不会跳转到这个“NotFound”标签。
如果你现在帮我解决这个问题,请...
谢谢