Expression.Add 方法

定義

建立 BinaryExpression,其代表不含溢位檢查的算術加法運算。

多載

Add(Expression, Expression)

建立 BinaryExpression,其代表不含溢位檢查的算術加法運算。

Add(Expression, Expression, MethodInfo)

建立 BinaryExpression,其代表不含溢位檢查的算術加法運算。 實作的方法可加以指定。

Add(Expression, Expression)

來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs

建立 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 屬性等於 Add,且 LeftRight 屬性設定為指定的值。

例外狀況

leftrightnull

不會為 left.Type 和 right.Type 定義 Addition 運算子。

範例

下列程式代碼範例示範如何建立新增兩個整數的表達式。

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

建立 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);
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 屬性等於 Add,且 LeftRightMethod 屬性設定為指定的值。

例外狀況

leftrightnull

method 不是 null,而它所代表的方法會傳回 void、不是 static (Visual Basic 中的 Shared),或者未確切採用兩個引數。

methodnull,而且未定義 left.Type 和 right.Type 的加法運算子。

備註

如需此 API 的詳細資訊,請參閱 Expression.Add 的補充 API 備註

適用於