Expression.Add 方法

定义

创建一个 BinaryExpression 表示没有溢出检查的算术加法运算。

重载

名称 说明
Add(Expression, Expression)

创建一个 BinaryExpression 表示没有溢出检查的算术加法运算。

Add(Expression, Expression, MethodInfo)

创建一个 BinaryExpression 表示没有溢出检查的算术加法运算。 可以指定实现方法。

Add(Expression, Expression)

创建一个 BinaryExpression 表示没有溢出检查的算术加法运算。

public:
 static System::Linq::Expressions::BinaryExpression ^ Add(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right);
public static System.Linq.Expressions.BinaryExpression Add(System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right);
static member Add : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BinaryExpression
Public Shared Function Add (left As Expression, right As Expression) As BinaryExpression

参数

left
Expression

一个 Expression 设置为 Left 等于的属性。

right
Expression

一个 Expression 设置为 Right 等于的属性。

返回

一个BinaryExpression属性NodeType等于AddLeftRight属性设置为指定值。

例外

leftrightnull.

没有为 left. 定义加法运算符。键入和 right。类型。

示例

下面的代码示例演示如何创建一个添加两个整数的表达式。

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

// This expression adds the values of its two arguments.
// Both arguments must be of the same type.
Expression sumExpr = Expression.Add(
    Expression.Constant(1),
    Expression.Constant(2)
);

// Print out the expression.
Console.WriteLine(sumExpr.ToString());

// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<int>>(sumExpr).Compile()());

// This code example produces the following output:
//
// (1 + 2)
// 3
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' This expression adds the values of its two arguments.
' Both arguments must be of the same type.
Dim sumExpr As Expression = Expression.Add(
    Expression.Constant(1),
    Expression.Constant(2)
    )

' Print the expression.
Console.WriteLine(sumExpr.ToString())

' The following statement first creates an expression tree,
' then compiles it, and then executes it.            
Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(sumExpr).Compile()())

' This code example produces the following output:
'
' (1 + 2)
' 3

注解

有关此 API 的详细信息,请参阅 Expression.Add 的补充 API 备注

适用于

Add(Expression, Expression, MethodInfo)

创建一个 BinaryExpression 表示没有溢出检查的算术加法运算。 可以指定实现方法。

public:
 static System::Linq::Expressions::BinaryExpression ^ Add(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.BinaryExpression Add(System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo method);
static member Add : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.BinaryExpression
Public Shared Function Add (left As Expression, right As Expression, method As MethodInfo) As BinaryExpression

参数

left
Expression

一个 Expression 设置为 Left 等于的属性。

right
Expression

一个 Expression 设置为 Right 等于的属性。

method
MethodInfo

一个 MethodInfo 设置为 Method 等于的属性。

返回

BinaryExpression一个属性NodeType等于AddLeftRightMethod属性设置为指定值。

例外

leftrightnull.

method 不是 null ,它表示的方法返回 void,不是 staticShared 在 Visual Basic 中),也不采用两个参数。

,并且未为 定义加法运算符。键入和 。类型。

注解

有关此 API 的详细信息,请参阅 Expression.Add 的补充 API 备注

适用于