C# Goto语句示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace goto_statement
{
class statement
{
static void Main(string[] args)
{
string name;
int marks;
label: //creating label with colon(:)
Console.WriteLine("Enter your name:");
name = Console.ReadLine();
Console.WriteLine("Welcome {0}", name);
Console.WriteLine("Enter your Marks:");
marks = Convert.ToInt32(Console.ReadLine());
goto label; //jump to label statement
}
}
}
goto 语句是 C# 中的跳转语句。
Goto 语句用于将控制直接转移到带标签的语句。 goto 语句对于摆脱深度嵌套的循环也很有用。
日期:2020-04-11 22:50:32 来源:oir作者:oir
