c#_goto语句

goto语句

在程序中我们可以给代码加上标签,这样就可以使用goto语句直接跳到标签的地方去执行
goto语句的语法
goto<1labelName>;
标签定义
<1labelName>

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _18
{
class
{
static void Main(string[] args)
{
int labal = 5;
goto mylabe;
labal++;//中间的代码就会被过滤掉,直接跳转到goto语句那
mylabe: Console.WriteLine(labal);
Console.ReadKey();
}
}
}