ILGenerator.DefineLabel Method

Declares a new label.

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

Syntax

'Declaration
Public Overridable Function DefineLabel As Label
public virtual Label DefineLabel()

Return Value

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

Remarks

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.

Examples

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.
'
Dim succeeded As Label = adderIL.DefineLabel()
Dim skipOutputInFinally As Label = adderIL.DefineLabel()
Dim skipOutputInCatch As Label = adderIL.DefineLabel()
// 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();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

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