Expression.Continue 方法

定義

建立代表 continue 陳述式的 GotoExpression

多載

Continue(LabelTarget)

建立代表 continue 陳述式的 GotoExpression

Continue(LabelTarget, Type)

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

Continue(LabelTarget)

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

建立代表 continue 陳述式的 GotoExpression

public:
 static System::Linq::Expressions::GotoExpression ^ Continue(System::Linq::Expressions::LabelTarget ^ target);
public static System.Linq.Expressions.GotoExpression Continue (System.Linq.Expressions.LabelTarget target);
static member Continue : System.Linq.Expressions.LabelTarget -> System.Linq.Expressions.GotoExpression
Public Shared Function Continue (target As LabelTarget) As GotoExpression

參數

target
LabelTarget

LabelTarget 將跳躍的目標 GotoExpression

傳回

GotoExpression,其 Kind 等於 Continue、Target 屬性設定為 target,且包含在跳躍時傳遞至目標標籤的 Null 值。

範例

下列範例示範如何建立使用 方法的 Continue 迴圈運算式。

// Add the following directive to your file:
// using System.Linq.Expressions;

// A label that is used by a break statement and a loop.
LabelTarget breakLabel = Expression.Label();

// A label that is used by the Continue statement and the loop it refers to.
LabelTarget continueLabel = Expression.Label();

// This expression represents a Continue statement.
Expression continueExpr = Expression.Continue(continueLabel);

// A variable that triggers the exit from the loop.
ParameterExpression count = Expression.Parameter(typeof(int));

// A loop statement.
Expression loopExpr = Expression.Loop(
    Expression.Block(
        Expression.IfThen(
            Expression.GreaterThan(count, Expression.Constant(3)),
            Expression.Break(breakLabel)
        ),
        Expression.PreIncrementAssign(count),
        Expression.Call(
                    null,
                    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
                    Expression.Constant("Loop")
                ),
        continueExpr,
        Expression.PreDecrementAssign(count)
    ),
    breakLabel,
    continueLabel
);

// The following statement first creates an expression tree,
// then compiles it, and then runs it.
// Without the Continue statement, the loop would go on forever.
Expression.Lambda<Action<int>>(loopExpr, count).Compile()(1);

// This code example produces the following output:
//
// Loop
// Loop
// Loop
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' A label that is used by a break statement and a loop. 
Dim breakLabel As LabelTarget = Expression.Label()

' A label that is used by the Continue statement and the loop it refers to.
Dim continueLabel As LabelTarget = Expression.Label()

' This expression represents a Continue statement.
Dim continueExpr As Expression = Expression.Continue(continueLabel)

' A variable that triggers the exit from the loop.
Dim count As ParameterExpression = Expression.Parameter(GetType(Integer))

' A loop statement.
Dim loopExpr As Expression = Expression.Loop(
       Expression.Block(
           Expression.IfThen(
               Expression.GreaterThan(count, Expression.Constant(3)),
               Expression.Break(breakLabel)
           ),
           Expression.PreIncrementAssign(count),
           Expression.Call(
                       Nothing,
                       GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}),
                       Expression.Constant("Loop")
                   ),
           continueExpr,
           Expression.PreDecrementAssign(count)
       ),
       breakLabel,
       continueLabel
   )

' The following statement first creates an expression tree,
' then compiles it, and then runs it.
' Without the Continue statement, the loop would go on forever.
Expression.Lambda(Of Action(Of Integer))(loopExpr, count).Compile()(1)

' This code example produces the following output:
'
' Loop
' Loop
' Loop

適用於

Continue(LabelTarget, Type)

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

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

public:
 static System::Linq::Expressions::GotoExpression ^ Continue(System::Linq::Expressions::LabelTarget ^ target, Type ^ type);
public static System.Linq.Expressions.GotoExpression Continue (System.Linq.Expressions.LabelTarget target, Type type);
static member Continue : System.Linq.Expressions.LabelTarget * Type -> System.Linq.Expressions.GotoExpression
Public Shared Function Continue (target As LabelTarget, type As Type) As GotoExpression

參數

target
LabelTarget

LabelTarget 將跳躍的目標 GotoExpression

type
Type

要將 Type 屬性設定為與之相等的 Type

傳回

GotoExpression,其 Kind 等於 Continue、Target 屬性設定為 targetType 屬性設定為 type,且包含在跳躍時傳遞至目標標籤的 null 值。

適用於