संपादित करें

इसके माध्यम से साझा किया गया


Expression.Add Method

Definition

Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking.

Overloads

Add(Expression, Expression)

Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking.

Add(Expression, Expression, MethodInfo)

Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking. The implementing method can be specified.

Add(Expression, Expression)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking.

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

Parameters

left
Expression

A Expression to set the Left property equal to.

right
Expression

A Expression to set the Right property equal to.

Returns

A BinaryExpression that has the NodeType property equal to Add and the Left and Right properties set to the specified values.

Exceptions

left or right is null.

The addition operator is not defined for left.Type and right.Type.

Examples

The following code example shows how to create an expression that adds two integers.

// 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

Remarks

For more information about this API, see Supplemental API remarks for Expression.Add.

Applies to

Add(Expression, Expression, MethodInfo)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

Creates a BinaryExpression that represents an arithmetic addition operation that does not have overflow checking. The implementing method can be specified.

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

Parameters

left
Expression

A Expression to set the Left property equal to.

right
Expression

A Expression to set the Right property equal to.

method
MethodInfo

A MethodInfo to set the Method property equal to.

Returns

A BinaryExpression that has the NodeType property equal to Add and the Left, Right and Method properties set to the specified values.

Exceptions

left or right is null.

method is not null and the method it represents returns void, is not static (Shared in Visual Basic), or does not take exactly two arguments.

method is null and the addition operator is not defined for left.Type and right.Type.

Remarks

For more information about this API, see Supplemental API remarks for Expression.Add.

Applies to