C#中的goto跳转语句

2022-10-08 12:45:25

goto的使用方法:

  1. goto语句不可以跳到for循环中。
  2. goto语句不可以跳到类的外面。
  3. goto语句不可以退出try{}catch()finally{}语句。
句型: goto label;
statement01;  //这句是跳过的语句
label:
statement02  //是执行的语句
eg: GoTo.cs
using System;

namespace GoTo
{
    class Program
    {
        static void Main() 
        {
            goto here;
                Console.WriteLine("First");

             here:
                Console.WriteLine("Second");
        }
    }
}


  • 作者:Moonython
  • 原文链接:https://blog.csdn.net/Moonython/article/details/8165465
    更新时间:2022-10-08 12:45:25