Expression.Goto 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建一个 GotoExpression 表示“go to”语句。
重载
| 名称 | 说明 |
|---|---|
| Goto(LabelTarget, Expression, Type) |
创建一个 GotoExpression 表示具有指定类型的“go to”语句。 可以指定跳转时传递给标签的值。 |
| Goto(LabelTarget, Type) |
创建一个 GotoExpression 表示具有指定类型的“go to”语句。 |
| Goto(LabelTarget) |
创建一个 GotoExpression 表示“go to”语句。 |
| Goto(LabelTarget, Expression) |
创建一个 GotoExpression 表示“go to”语句。 可以指定跳转时传递给标签的值。 |
Goto(LabelTarget, Expression, Type)
创建一个 GotoExpression 表示具有指定类型的“go to”语句。 可以指定跳转时传递给标签的值。
public:
static System::Linq::Expressions::GotoExpression ^ Goto(System::Linq::Expressions::LabelTarget ^ target, System::Linq::Expressions::Expression ^ value, Type ^ type);
public static System.Linq.Expressions.GotoExpression Goto(System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression value, Type type);
static member Goto : System.Linq.Expressions.LabelTarget * System.Linq.Expressions.Expression * Type -> System.Linq.Expressions.GotoExpression
Public Shared Function Goto (target As LabelTarget, value As Expression, type As Type) As GotoExpression
参数
- target
- LabelTarget
要 LabelTarget 跳到的 GotoExpression 那个。
- value
- Expression
跳转时传递给关联标签的值。
返回
一GotoExpressionKind个等于 Goto 的属性Target,属性设置为Typetarget,属性设置为type,并在value跳转时传递给目标标签。
适用于
Goto(LabelTarget, Type)
创建一个 GotoExpression 表示具有指定类型的“go to”语句。
public:
static System::Linq::Expressions::GotoExpression ^ Goto(System::Linq::Expressions::LabelTarget ^ target, Type ^ type);
public static System.Linq.Expressions.GotoExpression Goto(System.Linq.Expressions.LabelTarget target, Type type);
static member Goto : System.Linq.Expressions.LabelTarget * Type -> System.Linq.Expressions.GotoExpression
Public Shared Function Goto (target As LabelTarget, type As Type) As GotoExpression
参数
- target
- LabelTarget
要 LabelTarget 跳到的 GotoExpression 那个。
返回
一GotoExpressionKind个等于 Goto、Target属性设置为指定值、Type属性设置为 type 的属性,以及跳转时要传递给目标标签的 null 值。
适用于
Goto(LabelTarget)
创建一个 GotoExpression 表示“go to”语句。
public:
static System::Linq::Expressions::GotoExpression ^ Goto(System::Linq::Expressions::LabelTarget ^ target);
public static System.Linq.Expressions.GotoExpression Goto(System.Linq.Expressions.LabelTarget target);
static member Goto : System.Linq.Expressions.LabelTarget -> System.Linq.Expressions.GotoExpression
Public Shared Function Goto (target As LabelTarget) As GotoExpression
参数
- target
- LabelTarget
要 LabelTarget 跳到的 GotoExpression 那个。
返回
一GotoExpressionKind个等于 Goto 的属性Target设置为指定值,在跳转时要传递给目标标签的 null 值。
示例
以下示例演示如何创建包含 GotoExpression 对象的表达式。
// Add the following directive to your file:
// using System.Linq.Expressions;
// A label expression of the void type that is the target for the GotoExpression.
LabelTarget returnTarget = Expression.Label();
// This block contains a GotoExpression.
// 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("GoTo")),
Expression.Goto(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:
//
// GoTo
// "Other Work" is not printed because
// the GoTo expression transfers execution from Expression.GoTo(returnTarget)
// to Expression.Label(returnTarget).
' Add the following directive to your file:
' Imports System.Linq.Expressions
' A label expression of the void type that is the target for the GoToExpression.
Dim returnTarget As LabelTarget = Expression.Label()
' This block contains a GotoExpression.
' 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("GoTo")),
Expression.Goto(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:
'
' GoTo
' "Other Work" is not printed because
' the Return expression transfers execution from Expression.GoTo(returnTarget)
' to Expression.Label(returnTarget).
适用于
Goto(LabelTarget, Expression)
创建一个 GotoExpression 表示“go to”语句。 可以指定跳转时传递给标签的值。
public:
static System::Linq::Expressions::GotoExpression ^ Goto(System::Linq::Expressions::LabelTarget ^ target, System::Linq::Expressions::Expression ^ value);
public static System.Linq.Expressions.GotoExpression Goto(System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression value);
static member Goto : System.Linq.Expressions.LabelTarget * System.Linq.Expressions.Expression -> System.Linq.Expressions.GotoExpression
Public Shared Function Goto (target As LabelTarget, value As Expression) As GotoExpression
参数
- target
- LabelTarget
要 LabelTarget 跳到的 GotoExpression 那个。
- value
- Expression
跳转时传递给关联标签的值。
返回
一Kind个GotoExpression等于 Goto 的属性Target设置为target,并在value跳转时传递给目标标签。