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)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

创建一个表示 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

LabelTarget 将跳至的 GotoExpression

返回

一个 GotoExpression,其 Kind 等于 Return,其 Target 属性设置为 target,此外还有一个在跳转时将传递给目标标签的 null 值。

适用于

Return(LabelTarget, Expression)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

创建一个表示 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);
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 将跳至的 GotoExpression

value
Expression

将在跳转时传递给关联标签的值。

返回

一个 GotoExpression,其 Kind 等于 Continue,其 Target 属性设置为 target,此外还有一个在跳转时将传递给目标标签的 value

示例

以下示例演示如何创建包含 方法的 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)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

创建一个表示具有指定类型的 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

LabelTarget 将跳至的 GotoExpression

type
Type

要将 Type 属性设置为与其相等的 Type

返回

一个 GotoExpression,其 Kind 等于 Return,其 Target 属性设置为 target,并且其 Type 属性设置为 type,此外还有一个在跳转时将传递给目标标签的 null 值。

适用于

Return(LabelTarget, Expression, Type)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

创建一个表示具有指定类型的 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);
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 将跳至的 GotoExpression

value
Expression

将在跳转时传递给关联标签的值。

type
Type

要将 Type 属性设置为与其相等的 Type

返回

一个 GotoExpression,其 Kind 等于 Continue,其 Target 属性设置为 target,并且其 Type 属性设置为 type,此外还有一个在跳转时将传递给目标标签的 value

适用于