Expression.Label Expression.Label Expression.Label Expression.Label Method

定義

ラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label.

オーバーロード

Label() Label() Label() Label()

void 型で名前なしのラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with void type and no name.

Label(LabelTarget) Label(LabelTarget) Label(LabelTarget) Label(LabelTarget)

既定値のないラベルを表す LabelExpression を作成します。Creates a LabelExpression representing a label without a default value.

Label(String) Label(String) Label(String) Label(String)

指定された名前を持つ void 型のラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with void type and the given name.

Label(Type) Label(Type) Label(Type)

型を指定して、ラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with the given type.

Label(LabelTarget, Expression) Label(LabelTarget, Expression) Label(LabelTarget, Expression) Label(LabelTarget, Expression)

指定された既定値を持つラベルを表す LabelExpression を作成します。Creates a LabelExpression representing a label with the given default value.

Label(Type, String) Label(Type, String) Label(Type, String)

指定した型および名前を使用して、ラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with the given type and name.

Label() Label() Label() Label()

void 型で名前なしのラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with void type and no name.

public:
 static System::Linq::Expressions::LabelTarget ^ Label();
public static System.Linq.Expressions.LabelTarget Label ();
static member Label : unit -> System.Linq.Expressions.LabelTarget
Public Shared Function Label () As LabelTarget

戻り値

次の例を含む式を作成する方法を示します、LabelTargetオブジェクト。The following example demonstrates how to create an expression that contains a LabelTarget object.

// Add the following directive to the file:
// using System.Linq.Expressions;  

// A label expression of the void type that is the target for Expression.Return().
LabelTarget returnTarget = Expression.Label();

// This block contains a GotoExpression that represents a return statement with no value.
// It transfers execution to a label expression that is initialized with the same LabelTarget as the GotoExpression.
// The types of the GotoExpression, label expression, and LabelTarget must match.
BlockExpression blockExpr =
    Expression.Block(
        Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), Expression.Constant("Return")),
        Expression.Return(returnTarget),
        Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), Expression.Constant("Other Work")),
        Expression.Label(returnTarget)
    );

// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda<Action>(blockExpr).Compile()();

// This code example produces the following output:
//
// Return

// "Other Work" is not printed because 
// the Return expression transfers execution from Expression.Return(returnTarget)
// to Expression.Label(returnTarget).
' Add the following directive to the file:
' Imports System.Linq.Expressions  
' A label expression of the void type that is the target for Expression.Return().
Dim returnTarget As LabelTarget = Expression.Label()

' This block contains a GotoExpression that represents a return statement with no value.
' It transfers execution to a label expression that is initialized with the same LabelTarget as the GotoExpression.
' The types of the GotoExpression, label expression, and LabelTarget must match.
Dim blockExpr As BlockExpression =
      Expression.Block(
          Expression.Call(GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}), Expression.Constant("Return")),
          Expression.Return(returnTarget),
          Expression.Call(GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}), Expression.Constant("Other Work")),
          Expression.Label(returnTarget)
      )

' The following statement first creates an expression tree,
' then compiles it, and then runs it.
Expression.Lambda(Of Action)(blockExpr).Compile()()

' This code example produces the following output:
'
' Return

' "Other Work" is not printed because 
' the Return expression transfers execution from Return(returnTarget)
' to Expression.Label(returnTarget).

Label(LabelTarget) Label(LabelTarget) Label(LabelTarget) Label(LabelTarget)

既定値のないラベルを表す LabelExpression を作成します。Creates a LabelExpression representing a label without a default value.

public:
 static System::Linq::Expressions::LabelExpression ^ Label(System::Linq::Expressions::LabelTarget ^ target);
public static System.Linq.Expressions.LabelExpression Label (System.Linq.Expressions.LabelTarget target);
static member Label : System.Linq.Expressions.LabelTarget -> System.Linq.Expressions.LabelExpression
Public Shared Function Label (target As LabelTarget) As LabelExpression

パラメーター

target
LabelTarget LabelTarget LabelTarget LabelTarget

この LabelTarget が関連付けられる LabelExpressionThe LabelTarget which this LabelExpression will be associated with.

戻り値

Label(String) Label(String) Label(String) Label(String)

指定された名前を持つ void 型のラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with void type and the given name.

public:
 static System::Linq::Expressions::LabelTarget ^ Label(System::String ^ name);
public static System.Linq.Expressions.LabelTarget Label (string name);
static member Label : string -> System.Linq.Expressions.LabelTarget
Public Shared Function Label (name As String) As LabelTarget

パラメーター

name
String String String String

ラベルの名前。The name of the label.

戻り値

Label(Type) Label(Type) Label(Type)

型を指定して、ラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with the given type.

public:
 static System::Linq::Expressions::LabelTarget ^ Label(Type ^ type);
public static System.Linq.Expressions.LabelTarget Label (Type type);
static member Label : Type -> System.Linq.Expressions.LabelTarget

パラメーター

type
Type Type Type Type

ラベルにジャンプするときに渡す値の型。The type of value that is passed when jumping to the label.

戻り値

次の例では、使用する方法、LabelTargetループ式内のオブジェクト。The following example demonstrates how to use a LabelTarget object in a loop expression.

// Add the following directive to the file:
// using System.Linq.Expressions;  

// Creating a parameter expression.
ParameterExpression value = Expression.Parameter(typeof(int), "value");

// Creating an expression to hold a local variable. 
ParameterExpression result = Expression.Parameter(typeof(int), "result");

// Creating a label to jump to from a loop.
LabelTarget label = Expression.Label(typeof(int));

// Creating a method body.
BlockExpression block = Expression.Block(
    new[] { result },
    Expression.Assign(result, Expression.Constant(1)),
        Expression.Loop(
           Expression.IfThenElse(
               Expression.GreaterThan(value, Expression.Constant(1)),
               Expression.MultiplyAssign(result,
                   Expression.PostDecrementAssign(value)),
               Expression.Break(label, result)
           ),
       label
    )
);

// Compile and run an expression tree.
int factorial = Expression.Lambda<Func<int, int>>(block, value).Compile()(5);

Console.WriteLine(factorial);

// This code example produces the following output:
//
// 120
' Add the following directive to the file:
' Imports System.Linq.Expressions  
' Creating a parameter expression.
Dim value As ParameterExpression =
    Expression.Parameter(GetType(Integer), "value")

' Creating an expression to hold a local variable. 
Dim result As ParameterExpression =
    Expression.Parameter(GetType(Integer), "result")

' Creating a label to jump to from a loop.
Dim label As LabelTarget = Expression.Label(GetType(Integer))

' Creating a method body.
Dim block As BlockExpression = Expression.Block(
    New ParameterExpression() {result},
    Expression.Assign(result, Expression.Constant(1)),
    Expression.Loop(
        Expression.IfThenElse(
            Expression.GreaterThan(value, Expression.Constant(1)),
            Expression.MultiplyAssign(result,
                Expression.PostDecrementAssign(value)),
            Expression.Break(label, result)
        ),
        label
    )
)

' Compile an expression tree and return a delegate.
Dim factorial As Integer =
    Expression.Lambda(Of Func(Of Integer, Integer))(block, value).Compile()(5)

Console.WriteLine(factorial)

' This code example produces the following output:
'
' 120

Label(LabelTarget, Expression) Label(LabelTarget, Expression) Label(LabelTarget, Expression) Label(LabelTarget, Expression)

指定された既定値を持つラベルを表す LabelExpression を作成します。Creates a LabelExpression representing a label with the given default value.

public:
 static System::Linq::Expressions::LabelExpression ^ Label(System::Linq::Expressions::LabelTarget ^ target, System::Linq::Expressions::Expression ^ defaultValue);
public static System.Linq.Expressions.LabelExpression Label (System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression defaultValue);
static member Label : System.Linq.Expressions.LabelTarget * System.Linq.Expressions.Expression -> System.Linq.Expressions.LabelExpression
Public Shared Function Label (target As LabelTarget, defaultValue As Expression) As LabelExpression

パラメーター

target
LabelTarget LabelTarget LabelTarget LabelTarget

この LabelTarget が関連付けられる LabelExpressionThe LabelTarget which this LabelExpression will be associated with.

defaultValue
Expression Expression Expression Expression

通常の制御フローを経てラベルに到達した場合のこの LabelExpression の値。The value of this LabelExpression when the label is reached through regular control flow.

戻り値

指定された既定値を持つ LabelExpressionA LabelExpression with the given default value.

Label(Type, String) Label(Type, String) Label(Type, String)

指定した型および名前を使用して、ラベルを表す LabelTarget を作成します。Creates a LabelTarget representing a label with the given type and name.

public:
 static System::Linq::Expressions::LabelTarget ^ Label(Type ^ type, System::String ^ name);
public static System.Linq.Expressions.LabelTarget Label (Type type, string name);
static member Label : Type * string -> System.Linq.Expressions.LabelTarget

パラメーター

type
Type Type Type Type

ラベルにジャンプするときに渡す値の型。The type of value that is passed when jumping to the label.

name
String String String String

ラベルの名前。The name of the label.

戻り値

適用対象