Expression.Decrement 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建一个 UnaryExpression,它表示按 1 递减表达式值。
重载
Decrement(Expression) |
创建一个 UnaryExpression,它表示按 1 递减表达式值。 |
Decrement(Expression, MethodInfo) |
创建一个 UnaryExpression,它表示按 1 递减表达式值。 |
Decrement(Expression)
- Source:
- UnaryExpression.cs
- Source:
- UnaryExpression.cs
- Source:
- UnaryExpression.cs
创建一个 UnaryExpression,它表示按 1 递减表达式值。
public:
static System::Linq::Expressions::UnaryExpression ^ Decrement(System::Linq::Expressions::Expression ^ expression);
public static System.Linq.Expressions.UnaryExpression Decrement (System.Linq.Expressions.Expression expression);
static member Decrement : System.Linq.Expressions.Expression -> System.Linq.Expressions.UnaryExpression
Public Shared Function Decrement (expression As Expression) As UnaryExpression
参数
- expression
- Expression
要递减的 Expression。
返回
一个表示已递减的表达式的 UnaryExpression。
示例
下面的代码示例演示如何创建从给定值中减去 1 的表达式。
// Add the following directive to your file:
// using System.Linq.Expressions;
double num = 5.5;
// This expression represents a decrement operation
// that subtracts 1 from a value.
Expression decrementExpr = Expression.Decrement(
Expression.Constant(num)
);
// Print expression.
Console.WriteLine(decrementExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(
Expression.Lambda<Func<double>>(decrementExpr).Compile()());
// The value of the variable did not change,
// because the expression is functional.
Console.WriteLine("object: " + num);
// This code example produces the following output:
//
// Decrement(5.5)
// 4.5
// object: 5.5
' Add the following directive to your file:
' Imports System.Linq.Expressions
Dim num As Double = 5.5
' This expression represents a decrement operation
' that subtracts 1 from a value.
Dim decrementExpr As Expression = Expression.Decrement(
Expression.Constant(num)
)
' Print the expression.
Console.WriteLine(decrementExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(
Expression.Lambda(Of Func(Of Double))(decrementExpr).Compile()())
' The value of the variable did not change,
' because the expression is functional.
Console.WriteLine("object: " & num)
' This code example produces the following output:
'
' Decrement(5.5)
' 4.5
' object: 5.5
注解
此表达式是功能性的,不会更改传递给它的 对象的值。
适用于
Decrement(Expression, MethodInfo)
- Source:
- UnaryExpression.cs
- Source:
- UnaryExpression.cs
- Source:
- UnaryExpression.cs
创建一个 UnaryExpression,它表示按 1 递减表达式值。
public:
static System::Linq::Expressions::UnaryExpression ^ Decrement(System::Linq::Expressions::Expression ^ expression, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.UnaryExpression Decrement (System.Linq.Expressions.Expression expression, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.UnaryExpression Decrement (System.Linq.Expressions.Expression expression, System.Reflection.MethodInfo? method);
static member Decrement : System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.UnaryExpression
Public Shared Function Decrement (expression As Expression, method As MethodInfo) As UnaryExpression
参数
- expression
- Expression
要递减的 Expression。
- method
- MethodInfo
表示实现方法的 MethodInfo。
返回
一个表示已递减的表达式的 UnaryExpression。
注解
此表达式是功能性的,不会更改传递给它的 对象的值。