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。

适用于