Expression.Goto Метод

Определение

Создает объект GotoExpression, представляющий оператор goto.

Перегрузки

Goto(LabelTarget, Expression, Type)

Создает выражение GotoExpression, представляющее оператор goto с указанным типом. Можно указать значение, передаваемое метке при переходе.

Goto(LabelTarget, Type)

Создает выражение GotoExpression, представляющее оператор goto с указанным типом.

Goto(LabelTarget)

Создает объект GotoExpression, представляющий оператор goto.

Goto(LabelTarget, Expression)

Создает объект GotoExpression, представляющий оператор goto. Можно указать значение, передаваемое метке при переходе.

Goto(LabelTarget, Expression, Type)

Исходный код:
GotoExpression.cs
Исходный код:
GotoExpression.cs
Исходный код:
GotoExpression.cs

Создает выражение GotoExpression, представляющее оператор goto с указанным типом. Можно указать значение, передаваемое метке при переходе.

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

Значение, передаваемое связанной метке при переходе.

type
Type

Объект Type, который следует задать в качестве значения свойства Type.

Возвращаемое значение

GotoExpression, свойство Kind которого имеет значение Goto, свойство Targettarget, свойство Typetype, а при переходе целевой метке передается значение value.

Применяется к

Goto(LabelTarget, Type)

Исходный код:
GotoExpression.cs
Исходный код:
GotoExpression.cs
Исходный код:
GotoExpression.cs

Создает выражение GotoExpression, представляющее оператор goto с указанным типом.

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.

type
Type

Объект Type, который следует задать в качестве значения свойства Type.

Возвращаемое значение

GotoExpression, свойство Kind которого имеет значение Goto, свойство Target — указанное значение, свойство Type — значение в параметре type, а при переходе целевой метке передается значение NULL.

Применяется к

Goto(LabelTarget)

Исходный код:
GotoExpression.cs
Исходный код:
GotoExpression.cs
Исходный код:
GotoExpression.cs

Создает объект GotoExpression, представляющий оператор goto.

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.

Возвращаемое значение

GotoExpression, свойство Kind которого имеет значение 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.cs
Исходный код:
GotoExpression.cs
Исходный код:
GotoExpression.cs

Создает объект GotoExpression, представляющий оператор goto. Можно указать значение, передаваемое метке при переходе.

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

Значение, передаваемое связанной метке при переходе.

Возвращаемое значение

GotoExpression, свойство Kind которого имеет значение Goto, свойство Targettarget, а при переходе целевой метке передается значение value.

Применяется к