共用方式為


Expression.Break 方法

定義

建立表示 break 陳述式的 GotoExpression

多載

Break(LabelTarget)

建立表示 break 陳述式的 GotoExpression

Break(LabelTarget, Expression)

建立表示 break 陳述式的 GotoExpression。 可以指定跳躍時傳遞至標籤的值。

Break(LabelTarget, Type)

建立 GotoExpression,表示含指定之類型的 break 陳述式。

Break(LabelTarget, Expression, Type)

建立 GotoExpression,表示含指定之類型的 break 陳述式。 可以指定跳躍時傳遞至標籤的值。

Break(LabelTarget)

來源:
GotoExpression.cs
來源:
GotoExpression.cs
來源:
GotoExpression.cs

建立表示 break 陳述式的 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 等於 Break、Target 屬性設定為 target,且包含在跳躍時傳遞至目標標籤的 Null 值。

範例

下列範例示範如何建立包含使用 Break 方法之 對象的表達式LoopExpression

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

建立表示 break 陳述式的 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 等於 Break、Target 屬性設定為 target,且,且包含在跳躍時傳遞至目標標籤的 value

適用於

Break(LabelTarget, Type)

來源:
GotoExpression.cs
來源:
GotoExpression.cs
來源:
GotoExpression.cs

建立 GotoExpression,表示含指定之類型的 break 陳述式。

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,表示含指定之類型的 break 陳述式。 可以指定跳躍時傳遞至標籤的值。

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 等於 Break、Target 屬性設定為 targetType 屬性設定為 type,且包含在跳躍時傳遞至目標標籤的 value

適用於