您当前的位置: 首页 >  苍狼王unity学院 c#

补点C#基础_03_goto和return_区别

苍狼王unity学院 发布时间:2019-07-23 18:10:27 ,浏览量:3

1、goto
static void Main(string[] args)
{
int t = 1;
goto lable;
t++;
lable: Console.WriteLine(“有种你过来呀!”);
Console.WriteLine(t);
}
2、作用:
goto跳到指定的位置:
3、运行结果:
4、return

static void Main(string[] args)
{
int number = 1;
while (true)
{
number++;
if (number == 20)
{
return;
}
Console.WriteLine(number);
}

        Console.WriteLine("跳出循环了!");
        Console.ReadKey();

    }

5、作用:
return用来终止方法的,表示方法运行结束,剩余的代码不执行了!

6、运行结果

关注
打赏
查看更多评论

苍狼王unity学院

暂无认证

  • 3浏览

    0关注

    252博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录