Expression.Break Método

Definición

Crea un objeto GotoExpression que representa una instrucción break.

Sobrecargas

Nombre Description
Break(LabelTarget)

Crea un objeto GotoExpression que representa una instrucción break.

Break(LabelTarget, Expression)

Crea un objeto GotoExpression que representa una instrucción break. Se puede especificar el valor pasado a la etiqueta al saltar.

Break(LabelTarget, Type)

Crea un objeto GotoExpression que representa una instrucción break con el tipo especificado.

Break(LabelTarget, Expression, Type)

Crea un objeto GotoExpression que representa una instrucción break con el tipo especificado. Se puede especificar el valor pasado a la etiqueta al saltar.

Break(LabelTarget)

Crea un objeto GotoExpression que representa una instrucción break.

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

El LabelTarget al que GotoExpression saltará.

Devoluciones

con GotoExpressionKind igual a Break, la Target propiedad establecida targeten y un valor NULL que se pasará a la etiqueta de destino al saltar.

Ejemplos

En el ejemplo siguiente se muestra cómo crear una expresión que contenga un LoopExpression objeto que use el 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

Se aplica a

Break(LabelTarget, Expression)

Crea un objeto GotoExpression que representa una instrucción break. Se puede especificar el valor pasado a la etiqueta al saltar.

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

El LabelTarget al que GotoExpression saltará.

value
Expression

Valor que se pasará a la etiqueta asociada al saltar.

Devoluciones

con GotoExpressionKind igual a Break, la Target propiedad establecida targeten y value que se pasará a la etiqueta de destino al saltar.

Se aplica a

Break(LabelTarget, Type)

Crea un objeto GotoExpression que representa una instrucción break con el 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

El LabelTarget al que GotoExpression saltará.

type
Type

que Type se va a establecer la Type propiedad igual a.

Devoluciones

con GotoExpressionKind igual a Break, la Target propiedad establecida targeten y la Type propiedad establecida en type.

Se aplica a

Break(LabelTarget, Expression, Type)

Crea un objeto GotoExpression que representa una instrucción break con el tipo especificado. Se puede especificar el valor pasado a la etiqueta al saltar.

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

El LabelTarget al que GotoExpression saltará.

value
Expression

Valor que se pasará a la etiqueta asociada al saltar.

type
Type

que Type se va a establecer la Type propiedad igual a.

Devoluciones

con GotoExpressionKind igual a Break, la Target propiedad establecida targeten , la Type propiedad establecida typeen y value que se pasará a la etiqueta de destino al saltar.

Se aplica a