goto语句无条件转移控制到一个标签语句。它的一般形式如下,其中Identifier是标签语句的标识符:
goto Identifier;
class Program
{
static void Main(string[] args)
{
int x = 0;
while (true)
{
x++;
if (x == 1000)
{
goto NotSoGood;
}
}
NotSoGood: Console.WriteLine("结束");
Console.ReadKey();
}
}
goto语句必须在标签语句的作用域之内。
●goto语句可以跳到它本身所在块内的任何标签语句,或跳出到任何被嵌套的块内的标签语句。
●goto语句不能跳入任何嵌套在改语句本身所在块内部的任何块。
goto语句在switch语句内部
switch中使用goto语句