Expression.Break Método

Definición

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

Sobrecargas

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 que se pasa a la etiqueta cuando se produce el salto.

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 que se pasa a la etiqueta cuando se produce el salto.

Break(LabelTarget)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

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

LabelTarget al que saltará GotoExpression.

Devoluciones

GotoExpression con Kind igual a Break, la propiedad Target establecida en target 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 contiene un LoopExpression objeto que usa 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)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

Crea un objeto GotoExpression que representa una instrucción Break. Se puede especificar el valor que se pasa a la etiqueta cuando se produce el salto.

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

Parámetros

target
LabelTarget

LabelTarget al que saltará GotoExpression.

value
Expression

Valor que se va a pasar a la etiqueta asociada cuando se produzca el salto.

Devoluciones

GotoExpression con Kind igual a Break, la propiedad Target establecida en target y un value que se pasará a la etiqueta de destino al saltar.

Se aplica a

Break(LabelTarget, Type)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

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

LabelTarget al que saltará GotoExpression.

type
Type

Objeto Type en el que se va a establecer la propiedad Type.

Devoluciones

GotoExpression con Kind igual a Break, la propiedad Target establecida en target y la propiedad Type establecida en type.

Se aplica a

Break(LabelTarget, Expression, Type)

Source:
GotoExpression.cs
Source:
GotoExpression.cs
Source:
GotoExpression.cs

Crea un objeto GotoExpression que representa una instrucción Break con el tipo especificado. Se puede especificar el valor que se pasa a la etiqueta cuando se produce el salto.

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

Parámetros

target
LabelTarget

LabelTarget al que saltará GotoExpression.

value
Expression

Valor que se va a pasar a la etiqueta asociada cuando se produzca el salto.

type
Type

Objeto Type en el que se va a establecer la propiedad Type.

Devoluciones

GotoExpression con Kind igual a Break, la propiedad Target establecida en target, la propiedad Type establecida en type y un value que se pasará a la etiqueta de destino al saltar.

Se aplica a