共用方式為


Expression.Empty 方法

定義

建立具有 Void 類型的空運算式。

public:
 static System::Linq::Expressions::DefaultExpression ^ Empty();
public static System.Linq.Expressions.DefaultExpression Empty ();
static member Empty : unit -> System.Linq.Expressions.DefaultExpression
Public Shared Function Empty () As DefaultExpression

傳回

DefaultExpression,其 NodeType 屬性等於 Default,且 Type 屬性設為 Void

範例

下列程式代碼範例示範如何建立空的表達式,並將其新增至區塊表達式。

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

// This statement creates an empty expression.
DefaultExpression emptyExpr = Expression.Empty();

// The empty expression can be used where an expression is expected, but no action is desired.
// For example, you can use the empty expression as the last expression in the block expression.
// In this case the block expression's return value is void.
var emptyBlock = Expression.Block(emptyExpr);
' Add the following directive to your file:
' Imports System.Linq.Expressions 

' This statement creates an empty expression.
Dim emptyExpr As DefaultExpression = Expression.Empty()

' An empty expression can be used where an expression is expected but no action is desired.
' For example, you can use an empty expression as the last expression in a block expression.
' In this case, the block expression's return value is void.
Dim emptyBlock = Expression.Block(emptyExpr)

備註

空的表達式可用於預期表達式,但不需要採取任何動作。 例如,您可以使用空運算式做為區塊表達式的最後一個表達式。 在此情況下,區塊表達式的傳回值為 void。

適用於