using System;
namespace Goto
{
/// <summary>
/// C#中使用goto
/// </summary>
class Program
{
static void Main()
{
Console.Title = "C#中使用goto";
UseGoto();
Console.ReadKey();
}
static void UseGoto()
{
// goto語句的用法非常靈活,你可以用它實現很多功能,但是由於goto語句的跳轉影響程序的結構,在使用的時候會使人迷茫,所以一般"教材"上都不建議使用,
// 但是用它可以實現遞歸,循環,選擇功能,使用起來也很方便,存在即有價值,大家在使用上做適當取舍就好,覺得需要用就用,不必因拘泥而刻意不去用
int i = 0;
cc: Console.Write(i + Environment.NewLine);
if (i < 9)
{
i++;
goto cc;
}
Console.Write("Please enter your message:");
string message = Console.ReadLine();
goto P;
P: Console.WriteLine("-----------------------------------------------------");
Console.WriteLine(message);
}
}
}
