Expression.Subtract 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建一个表示不进行溢出检查的算术减法运算的 BinaryExpression。
重载
Subtract(Expression, Expression) |
创建一个表示不进行溢出检查的算术减法运算的 BinaryExpression。 |
Subtract(Expression, Expression, MethodInfo) |
创建一个表示不进行溢出检查的算术减法运算的 BinaryExpression。 |
Subtract(Expression, Expression)
创建一个表示不进行溢出检查的算术减法运算的 BinaryExpression。
public:
static System::Linq::Expressions::BinaryExpression ^ Subtract(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right);
public static System.Linq.Expressions.BinaryExpression Subtract (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right);
static member Subtract : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BinaryExpression
Public Shared Function Subtract (left As Expression, right As Expression) As BinaryExpression
参数
- left
- Expression
要将 Expression 属性设置为与其相等的 Left。
- right
- Expression
要将 Expression 属性设置为与其相等的 Right。
返回
一个 BinaryExpression,其 NodeType 属性等于 Subtract,并且其 Left 和 Right 属性设置为指定值。
例外
left
或 right
为 null
。
没有为 left
.Type 和 right
.Type 定义减法运算符。
示例
下面的代码示例演示如何创建一个表达式,该表达式从第一个参数中减去参数。
// Add the following directive to your file:
// using System.Linq.Expressions;
// This expression subtracts the second argument
// from the first argument.
// Both arguments must be of the same type.
Expression subtractExpr = Expression.Subtract(
Expression.Constant(12),
Expression.Constant(3)
);
// Print out the expression.
Console.WriteLine(subtractExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<int>>(subtractExpr).Compile().Invoke());
// This code example produces the following output:
//
// (12 - 3)
// 9
' Add the following directive to your file:
' Imports System.Linq.Expressions
' This expression subtracts the second argument
' from the first argument.
' Both arguments must be of the same type.
Dim subtractExpr As Expression = Expression.Subtract(
Expression.Constant(12),
Expression.Constant(3)
)
' Print the expression.
Console.WriteLine(subtractExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(subtractExpr).Compile()())
' This code example produces the following output:
'
' (12 - 3)
' 9
注解
生成的BinaryExpressionMethod属性设置为实现方法。 此属性 Type 设置为节点的类型。 如果提升节点,则 IsLifted 两 IsLiftedToNull 者均 true
具有属性。 否则,它们是 false
。 Conversion 属性为 null
。
以下信息描述了实现方法、节点类型以及节点是否已提升。
实现方法
以下规则确定操作的所选实现方法:
Type如果任
left
一或right
表示重载减法运算符的用户定义类型的属性,则MethodInfo表示该方法是实现方法。否则,如果
left
为 .键入和right
。类型为数值类型,实现方法为null
。
节点类型和提升与非提升
如果实现方法不是 null
:
如果
left
。键入和right
。类型可分配给实现方法的相应参数类型,不会提升节点。 节点的类型是实现方法的返回类型。如果满足以下两个条件,则会提升节点,节点的类型是对应于实现方法的返回类型的可为 null 类型:
left
.键入和right
。类型都是至少一个可为 null 的值类型,相应的不可为 null 类型等于实现方法的相应参数类型。实现方法的返回类型是不可为 null 的值类型。
如果实现方法是 null
:
如果
left
。键入和right
。类型都是不可为 null 的,节点不会提升。 节点的类型是预定义减法运算符的结果类型。如果
left
。键入和right
。类型既可为 null,又可提升节点。 节点的类型是与预定义减法运算符的结果类型相对应的可为 null 类型。
适用于
Subtract(Expression, Expression, MethodInfo)
创建一个表示不进行溢出检查的算术减法运算的 BinaryExpression。
public:
static System::Linq::Expressions::BinaryExpression ^ Subtract(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.BinaryExpression Subtract (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.BinaryExpression Subtract (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo? method);
static member Subtract : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.BinaryExpression
Public Shared Function Subtract (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 属性等于 Subtract,并且其 Left、Right 和 Method 属性设置为指定值。
例外
left
或 right
为 null
。
method
不是 null
,它所表示的方法返回 void
,而不是 static
(Visual Basic 中为 Shared
),或者并非采用两个参数。
method
是 null
,且没有为 left
.Type 和 right
.Type 定义减法运算符。
注解
生成的BinaryExpressionMethod属性设置为实现方法。 此属性 Type 设置为节点的类型。 如果提升节点,则 IsLifted 两 IsLiftedToNull 者均 true
具有属性。 否则,它们是 false
。 Conversion 属性为 null
。
以下信息描述了实现方法、节点类型以及节点是否已提升。
实现方法
以下规则确定操作的实现方法:
如果
method
不是null
并且它表示一个非 void,static
则表示采用两个参数的 Visual Basic) 方法中的 (Shared
,它是节点的实现方法。否则,如果Type任一或
right
表示重载减法运算符的用户定义类型的属性,则MethodInfo表示该方法left
是实现方法。否则,如果
left
为 .键入和right
。类型为数值类型,实现方法为null
。
节点类型和提升与非提升
如果实现方法不是 null
:
如果
left
。键入和right
。类型可分配给实现方法的相应参数类型,不会提升节点。 节点的类型是实现方法的返回类型。如果满足以下两个条件,则会提升节点,节点的类型是对应于实现方法的返回类型的可为 null 类型:
left
.键入和right
。类型都是至少一个可为 null 的值类型,相应的不可为 null 类型等于实现方法的相应参数类型。实现方法的返回类型是不可为 null 的值类型。
如果实现方法为 null
:
如果
left
。键入和right
。类型都是不可为 null 的,节点不会解除。 节点的类型是预定义减法运算符的结果类型。如果
left
。键入和right
。类型都是可为 null 的,节点会提升。 节点的类型是与预定义减法运算符的结果类型相对应的可以为 null 的类型。