goto的使用方法:
- goto语句不可以跳到for循环中。
- goto语句不可以跳到类的外面。
- 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");
}
}
}
本文详细介绍了goto语句的基本用法及限制条件,并通过一个简单的C#示例展示了如何正确使用goto语句来实现特定的流程控制。文章强调了goto语句不可用于跳转到for循环、类外部及try-catch-finally块之外的特点。
637

被折叠的 条评论
为什么被折叠?



