Expression.Return 方法

定義

建立 GotoExpression,表示 return 陳述式。Creates a GotoExpression representing a return statement.

多載

Return(LabelTarget)

建立 GotoExpression,表示 return 陳述式。Creates a GotoExpression representing a return statement.

Return(LabelTarget, Expression)

建立 GotoExpression,表示 return 陳述式。Creates a GotoExpression representing a return statement. 可以指定跳躍時傳遞至標籤的值。The value passed to the label upon jumping can be specified.

Return(LabelTarget, Type)

建立 GotoExpression,表示含指定之類型的 return 陳述式。Creates a GotoExpression representing a return statement with the specified type.

Return(LabelTarget, Expression, Type)

建立 GotoExpression,表示含指定之類型的 return 陳述式。Creates a GotoExpression representing a return statement with the specified type. 可以指定跳躍時傳遞至標籤的值。The value passed to the label upon jumping can be specified.

Return(LabelTarget)

建立 GotoExpression,表示 return 陳述式。Creates a GotoExpression representing a return statement.

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

LabelTarget 將跳躍的目標 GotoExpressionThe LabelTarget that the GotoExpression will jump to.

傳回

GotoExpression

GotoExpression,其 Kind 等於 Return、Target 屬性設定為 target,且包含在跳躍時傳遞至目標標籤的 Null 值。A GotoExpression with Kind equal to Return, the Target property set to target, and a null value to be passed to the target label upon jumping.

適用於

Return(LabelTarget, Expression)

建立 GotoExpression,表示 return 陳述式。Creates a GotoExpression representing a return statement. 可以指定跳躍時傳遞至標籤的值。The value passed to the label upon jumping can be specified.

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);
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

LabelTarget 將跳躍的目標 GotoExpressionThe LabelTarget that the GotoExpression will jump to.

value
Expression

將在跳躍時傳遞至關聯標籤的值。The value that will be passed to the associated label upon jumping.

傳回

GotoExpression

GotoExpression,其 Kind 等於 Continue、Target 屬性設定為 target,且,且包含在跳躍時傳遞至目標標籤的 valueA GotoExpression with Kind equal to Continue, the Target property set to target, and value to be passed to the target label upon jumping.

範例

下列範例示範如何建立包含方法的運算式 ReturnThe following example demonstrates how to create an expression that contains the Return method.

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

建立 GotoExpression,表示含指定之類型的 return 陳述式。Creates a GotoExpression representing a return statement with the specified type.

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

LabelTarget 將跳躍的目標 GotoExpressionThe LabelTarget that the GotoExpression will jump to.

type
Type

要將 Type 屬性設定為與之相等的 TypeAn Type to set the Type property equal to.

傳回

GotoExpression

GotoExpression,其 Kind 等於 Return、Target 屬性設定為 targetType 屬性設定為 type,且包含在跳躍時傳遞至目標標籤的 null 值。A GotoExpression with Kind equal to Return, the Target property set to target, the Type property set to type, and a null value to be passed to the target label upon jumping.

適用於

Return(LabelTarget, Expression, Type)

建立 GotoExpression,表示含指定之類型的 return 陳述式。Creates a GotoExpression representing a return statement with the specified type. 可以指定跳躍時傳遞至標籤的值。The value passed to the label upon jumping can be specified.

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);
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

LabelTarget 將跳躍的目標 GotoExpressionThe LabelTarget that the GotoExpression will jump to.

value
Expression

將在跳躍時傳遞至關聯標籤的值。The value that will be passed to the associated label upon jumping.

type
Type

要將 Type 屬性設定為與之相等的 TypeAn Type to set the Type property equal to.

傳回

GotoExpression

GotoExpression,其 Kind 等於Continue、Target 屬性設定為 targetType 屬性設定為 type,且包含在跳躍時傳遞至目標標籤的 valueA GotoExpression with Kind equal to Continue, the Target property set to target, the Type property set to type, and value to be passed to the target label upon jumping.

適用於