語言

Expression.Break 方法

定義

建立 GotoExpression 一個代表中斷陳述句的符號。

多載

名稱 Description
Break(LabelTarget)

建立 GotoExpression 一個代表中斷陳述句的符號。

Break(LabelTarget, Expression)

建立 GotoExpression 一個代表中斷陳述句的符號。 跳躍時傳遞給標籤的值可以指定。

Break(LabelTarget, Type)

建立 GotoExpression 一個代表指定型別的中斷陳述句。

Break(LabelTarget, Expression, Type)

建立 GotoExpression 一個代表指定型別的中斷陳述句。 跳躍時傳遞給標籤的值可以指定。

Break(LabelTarget)

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

建立 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 A 中 Kind Break 為 ,Target屬性設為 target,跳躍時需傳遞一個空值。

範例

以下範例示範如何建立包含 LoopExpression 使用該 Break 方法的物件的表達式。

// 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
來源:
GotoExpression.cs
來源:
GotoExpression.cs

建立 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 A 等Kind於 Break,Target屬性設為 target,value跳躍時傳給目標標籤。

適用於

Break(LabelTarget, Type)

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

建立 GotoExpression 一個代表指定型別的中斷陳述句。

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 A 將屬性Type設為 。

傳回

GotoExpression A 等Kind於 Break,Target屬性設為 target,屬性設Type為 。type

適用於

Break(LabelTarget, Expression, Type)

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

建立 GotoExpression 一個代表指定型別的中斷陳述句。 跳躍時傳遞給標籤的值可以指定。

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 A 將屬性Type設為 。

傳回

GotoExpression A 中 等Kind於 Break,屬性Target設為 target,Type屬性設為 type,value且跳躍時傳給目標標籤。

適用於