Expression.Break Метод

Определение

GotoExpression Создает оператор останова.

Перегрузки

Имя Описание
Break(LabelTarget)

GotoExpression Создает оператор останова.

Break(LabelTarget, Expression)

GotoExpression Создает оператор останова. Можно указать значение, переданное меткой при переходе.

Break(LabelTarget, Type)

GotoExpression Создает оператор останова с указанным типом.

Break(LabelTarget, Expression, Type)

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

Break(LabelTarget)

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

GotoExpression Создает оператор останова.

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

Параметры

target
LabelTarget

LabelTarget Это GotoExpression будет переходить к.

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

Значение GotoExpression со Kind значением "Разрыв", свойство Targetимеет target значение NULL, передаваемое целевой меткой при переходе.

Примеры

В следующем примере показано, как создать выражение, содержащее LoopExpression объект, использующий Break метод.

// Add the following directive to the file:
// using System.Linq.Expressions;

// Creating a parameter expression.
ParameterExpression value = Expression.Parameter(typeof(int), "value");

// Creating an expression to hold a local variable.
ParameterExpression result = Expression.Parameter(typeof(int), "result");

// Creating a label to jump to from a loop.
LabelTarget label = Expression.Label(typeof(int));

// Creating a method body.
BlockExpression block = Expression.Block(
    new[] { result },
    Expression.Assign(result, Expression.Constant(1)),
        Expression.Loop(
           Expression.IfThenElse(
               Expression.GreaterThan(value, Expression.Constant(1)),
               Expression.MultiplyAssign(result,
                   Expression.PostDecrementAssign(value)),
               Expression.Break(label, result)
           ),
       label
    )
);

// Compile and run an expression tree.
int factorial = Expression.Lambda<Func<int, int>>(block, value).Compile()(5);

Console.WriteLine(factorial);

// This code example produces the following output:
//
// 120
' Add the following directive to the file:
' Imports System.Linq.Expressions  

' Creating a parameter expression.
Dim value As ParameterExpression =
    Expression.Parameter(GetType(Integer), "value")

' Creating an expression to hold a local variable. 
Dim result As ParameterExpression =
    Expression.Parameter(GetType(Integer), "result")

' Creating a label to jump to from a loop.
Dim label As LabelTarget = Expression.Label(GetType(Integer))

' Creating a method body.
Dim block As BlockExpression = Expression.Block(
    New ParameterExpression() {result},
    Expression.Assign(result, Expression.Constant(1)),
    Expression.Loop(
        Expression.IfThenElse(
            Expression.GreaterThan(value, Expression.Constant(1)),
            Expression.MultiplyAssign(result,
                Expression.PostDecrementAssign(value)),
            Expression.Break(label, result)
        ),
        label
    )
)

' Compile an expression tree and return a delegate.
Dim factorial As Integer =
    Expression.Lambda(Of Func(Of Integer, Integer))(block, value).Compile()(5)

Console.WriteLine(factorial)

' This code example produces the following output:
'
' 120

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

Break(LabelTarget, Expression)

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

GotoExpression Создает оператор останова. Можно указать значение, переданное меткой при переходе.

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

Параметры

target
LabelTarget

LabelTarget Это GotoExpression будет переходить к.

value
Expression

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

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

Значение GotoExpression со Kind значением "Разрыв", Target свойство targetимеет значение и value передается в целевую метку при переходе.

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

Break(LabelTarget, Type)

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

GotoExpression Создает оператор останова с указанным типом.

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

Параметры

target
LabelTarget

LabelTarget Это GotoExpression будет переходить к.

type
Type

Значение Type , равное свойству Type .

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

Значение GotoExpression с Kind равным Break, свойствуTarget, target заданному , и свойствуType, заданному typeв значение .

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

Break(LabelTarget, Expression, Type)

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

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

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

Параметры

target
LabelTarget

LabelTarget Это GotoExpression будет переходить к.

value
Expression

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

type
Type

Значение Type , равное свойству Type .

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

Значение GotoExpression с Kind равным "Разрыв", свойство Targetимеет значение , targetType свойство, заданное typeзначением, и value передается целевой метки при переходе.

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