Expression.Break Método

Definição

Cria uma GotoExpression que representa uma instrução de quebra.

Sobrecargas

Name Description
Break(LabelTarget)

Cria uma GotoExpression que representa uma instrução de quebra.

Break(LabelTarget, Expression)

Cria uma GotoExpression que representa uma instrução de quebra. O valor passado para a etiqueta ao saltar pode ser especificado.

Break(LabelTarget, Type)

Cria uma GotoExpression representação de uma instrução break com o tipo especificado.

Break(LabelTarget, Expression, Type)

Cria uma GotoExpression representação de uma instrução break com o tipo especificado. O valor passado para a etiqueta ao saltar pode ser especificado.

Break(LabelTarget)

Cria uma GotoExpression que representa uma instrução de quebra.

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

Parâmetros

target
LabelTarget

O LabelTarget que vai GotoExpression saltar para.

Devoluções

A com Kind igual a Break, a Target propriedade definida GotoExpression para target, e um valor nulo a ser passado para a etiqueta de destino ao saltar.

Exemplos

O exemplo seguinte demonstra como criar uma expressão que contenha um LoopExpression objeto que utiliza o Break método.

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

Aplica-se a

Break(LabelTarget, Expression)

Cria uma GotoExpression que representa uma instrução de quebra. O valor passado para a etiqueta ao saltar pode ser especificado.

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

Parâmetros

target
LabelTarget

O LabelTarget que vai GotoExpression saltar para.

value
Expression

O valor que será passado para a etiqueta associada ao saltar.

Devoluções

A GotoExpression com Kind igual a Break, a Target propriedade definida como target, e value deve ser passada para o rótulo alvo ao saltar.

Aplica-se a

Break(LabelTarget, Type)

Cria uma GotoExpression representação de uma instrução break com o tipo especificado.

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

Parâmetros

target
LabelTarget

O LabelTarget que vai GotoExpression saltar para.

type
Type

E Type para definir a Type propriedade igual a .

Devoluções

A GotoExpression com Kind igual a Quebra, a Target propriedade definida a target, e a Type propriedade definida a type.

Aplica-se a

Break(LabelTarget, Expression, Type)

Cria uma GotoExpression representação de uma instrução break com o tipo especificado. O valor passado para a etiqueta ao saltar pode ser especificado.

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

Parâmetros

target
LabelTarget

O LabelTarget que vai GotoExpression saltar para.

value
Expression

O valor que será passado para a etiqueta associada ao saltar.

type
Type

E Type para definir a Type propriedade igual a .

Devoluções

A GotoExpression com Kind igual a Break, a Target propriedade definida para target, a Type propriedade definida para type, e value para ser passada para a etiqueta de destino ao saltar.

Aplica-se a