Expression.Return メソッド

定義

return ステートメントを表す GotoExpression を作成します。

オーバーロード

名前 説明
Return(LabelTarget)

return ステートメントを表す GotoExpression を作成します。

Return(LabelTarget, Expression)

return ステートメントを表す GotoExpression を作成します。 ジャンプ時にラベルに渡される値を指定できます。

Return(LabelTarget, Type)

指定した型の return ステートメントを表す GotoExpression を作成します。

Return(LabelTarget, Expression, Type)

指定した型の return ステートメントを表す GotoExpression を作成します。 ジャンプ時にラベルに渡される値を指定できます。

Return(LabelTarget)

return ステートメントを表す GotoExpression を作成します。

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

パラメーター

target
LabelTarget

GotoExpressionがジャンプするLabelTarget

返品

Kind Return と等しいGotoExpressionTarget プロパティが target に設定され、ジャンプ時にターゲット ラベルに渡される null 値。

適用対象

Return(LabelTarget, Expression)

return ステートメントを表す GotoExpression を作成します。 ジャンプ時にラベルに渡される値を指定できます。

public:
 static System::Linq::Expressions::GotoExpression ^ Return(System::Linq::Expressions::LabelTarget ^ target, System::Linq::Expressions::Expression ^ value);
public static System.Linq.Expressions.GotoExpression Return(System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression value);
static member Return : System.Linq.Expressions.LabelTarget * System.Linq.Expressions.Expression -> System.Linq.Expressions.GotoExpression
Public Shared Function Return (target As LabelTarget, value As Expression) As GotoExpression

パラメーター

target
LabelTarget

GotoExpressionがジャンプするLabelTarget

value
Expression

ジャンプ時に関連付けられているラベルに渡される値。

返品

Kind Continue と等しく、Target プロパティが target に設定され、ジャンプ時にターゲット ラベルに渡されるvalueを持つGotoExpression

次の例では、 Return メソッドを含む式を作成する方法を示します。

// 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).

適用対象

Return(LabelTarget, Type)

指定した型の return ステートメントを表す GotoExpression を作成します。

public:
 static System::Linq::Expressions::GotoExpression ^ Return(System::Linq::Expressions::LabelTarget ^ target, Type ^ type);
public static System.Linq.Expressions.GotoExpression Return(System.Linq.Expressions.LabelTarget target, Type type);
static member Return : System.Linq.Expressions.LabelTarget * Type -> System.Linq.Expressions.GotoExpression
Public Shared Function Return (target As LabelTarget, type As Type) As GotoExpression

パラメーター

target
LabelTarget

GotoExpressionがジャンプするLabelTarget

type
Type

Type プロパティを等しい値に設定するType

返品

Return と等しいKindを持つGotoExpressionTarget プロパティを target に設定し、Type プロパティを type に設定し、ジャンプ時にターゲット ラベルに渡す null 値を指定します。

適用対象

Return(LabelTarget, Expression, Type)

指定した型の return ステートメントを表す GotoExpression を作成します。 ジャンプ時にラベルに渡される値を指定できます。

public:
 static System::Linq::Expressions::GotoExpression ^ Return(System::Linq::Expressions::LabelTarget ^ target, System::Linq::Expressions::Expression ^ value, Type ^ type);
public static System.Linq.Expressions.GotoExpression Return(System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression value, Type type);
static member Return : System.Linq.Expressions.LabelTarget * System.Linq.Expressions.Expression * Type -> System.Linq.Expressions.GotoExpression
Public Shared Function Return (target As LabelTarget, value As Expression, type As Type) As GotoExpression

パラメーター

target
LabelTarget

GotoExpressionがジャンプするLabelTarget

value
Expression

ジャンプ時に関連付けられているラベルに渡される値。

type
Type

Type プロパティを等しい値に設定するType

返品

Kindが Continue に等しいGotoExpressionTarget プロパティが target に設定され、Type プロパティがtypeに設定され、ジャンプ時にターゲット ラベルに渡されるvalue

適用対象