C#中的代码好奇心

Ty.*_*Ty. 1 c# label goto

我正在查看YUI Compressor,并在ECMA.NET项目中遇到了这段代码(如果您感兴趣,可以使用Continuation文件).

protected internal override int FindPrototypeId (string s)
    {
        int id;
        #region Generated PrototypeId Switch
    L0: {
            id = 0;
            string X = null;
            if (s.Length == 11) { X = "constructor"; id = Id_constructor; }
            if (X != null && X != s && !X.Equals (s))
                id = 0;
        }
    EL0:
        #endregion
        return id;
    }
Run Code Online (Sandbox Code Playgroud)

我不知道L0:和EL0:在这里做什么,以前从未见过这个.这个词对谷歌来说似乎也太基础了.

有人知道这是什么一回事吗?

Sco*_*man 9

它们看起来像是用作goto目标的标签.有关更多信息,请参见http://msdn.microsoft.com/en-us/library/13940fs2.aspx.


Jor*_*ner 5

它们看起来像我的标签.在这个例子中没有使用标签(因为它是生成的代码?),但可以用来跳转到另一个地方.您可以使用goto L0;跳转第一个标签.作为一个例子,下面的代码只写"Hello,World",因为它跳过了中间Write():

Console.Write("Hello, ");
goto Last;
Console.Write("Cruel ");
Last:
Console.WriteLine("World");
Run Code Online (Sandbox Code Playgroud)