ILGenerator.DefineLabel Method

Declares a new label.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public virtual Label DefineLabel()

Return Value

Type: System.Reflection.Emit.Label
A new label that can be used as a token for branching.

The label is just a token and does not yet represent any particular location within the stream. To set the position of the label within the stream, you must call the MarkLabel method.

The following example demonstrates the use of the DefineLabel method to define three labels. This code is part of a larger example provided for the BeginExceptionBlock method.


// Define labels for branching. The labels can be used immediately in Emit
// calls, but they do not acquire their target locations until the 
// MarkLabel(Label) method is called at the location in the program that
// the label applies to.
//
Label succeeded = adderIL.DefineLabel();
Label skipOutputInFinally = adderIL.DefineLabel();
Label skipOutputInCatch = adderIL.DefineLabel();


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: