Expression.Break Méthode

Définition

Crée un représentant une GotoExpression instruction break.

Surcharges

Nom Description
Break(LabelTarget)

Crée un représentant une GotoExpression instruction break.

Break(LabelTarget, Expression)

Crée un représentant une GotoExpression instruction break. La valeur transmise à l’étiquette lors du saut peut être spécifiée.

Break(LabelTarget, Type)

Crée une instruction représentant une GotoExpression instruction break avec le type spécifié.

Break(LabelTarget, Expression, Type)

Crée une instruction représentant une GotoExpression instruction break avec le type spécifié. La valeur transmise à l’étiquette lors du saut peut être spécifiée.

Break(LabelTarget)

Crée un représentant une GotoExpression instruction 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

Paramètres

target
LabelTarget

GotoExpression La LabelTarget volonté de sauter.

Retours

Kind Égal GotoExpression à Break, la Target propriété définie sur target, et une valeur Null à passer à l’étiquette cible lors du saut.

Exemples

L’exemple suivant montre comment créer une expression qui contient un LoopExpression objet qui utilise la Break méthode.

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

S’applique à

Break(LabelTarget, Expression)

Crée un représentant une GotoExpression instruction break. La valeur transmise à l’étiquette lors du saut peut être spécifiée.

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

Paramètres

target
LabelTarget

GotoExpression La LabelTarget volonté de sauter.

value
Expression

Valeur qui sera transmise à l’étiquette associée lors du saut.

Retours

Kind Égal GotoExpression à Break, la Target propriété définie targetsur , et value à passer à l’étiquette cible lors du saut.

S’applique à

Break(LabelTarget, Type)

Crée une instruction représentant une GotoExpression instruction break avec le type spécifié.

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

Paramètres

target
LabelTarget

GotoExpression La LabelTarget volonté de sauter.

type
Type

Pour Type définir la Type propriété égale à.

Retours

Égal GotoExpression à Break, la Target propriété définie targetsur , et la Type propriété définie sur type.Kind

S’applique à

Break(LabelTarget, Expression, Type)

Crée une instruction représentant une GotoExpression instruction break avec le type spécifié. La valeur transmise à l’étiquette lors du saut peut être spécifiée.

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

Paramètres

target
LabelTarget

GotoExpression La LabelTarget volonté de sauter.

value
Expression

Valeur qui sera transmise à l’étiquette associée lors du saut.

type
Type

Pour Type définir la Type propriété égale à.

Retours

Kind Égal GotoExpression à Break, la Target propriété définie targetsur , la Type propriété définie typesur et value à passer à l’étiquette cible lors du saut.

S’applique à