Expression.Decrement Method

Definition

Creates a UnaryExpression that represents the decrementing of the expression by 1.

Overloads

Decrement(Expression)

Creates a UnaryExpression that represents the decrementing of the expression by 1.

Decrement(Expression, MethodInfo)

Creates a UnaryExpression that represents the decrementing of the expression by 1.

Decrement(Expression)

Source:
UnaryExpression.cs
Source:
UnaryExpression.cs
Source:
UnaryExpression.cs

Creates a UnaryExpression that represents the decrementing of the expression by 1.

public static System.Linq.Expressions.UnaryExpression Decrement (System.Linq.Expressions.Expression expression);

Parameters

expression
Expression

An Expression to decrement.

Returns

A UnaryExpression that represents the decremented expression.

Examples

The following code example shows how to create an expression that subtracts 1 from a given value.

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

Remarks

This expression is functional and does not change the value of the object passed to it.

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Decrement(Expression, MethodInfo)

Source:
UnaryExpression.cs
Source:
UnaryExpression.cs
Source:
UnaryExpression.cs

Creates a UnaryExpression that represents the decrementing of the expression by 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);

Parameters

expression
Expression

An Expression to decrement.

method
MethodInfo

A MethodInfo that represents the implementing method.

Returns

A UnaryExpression that represents the decremented expression.

Remarks

This expression is functional and does not change the value of the object passed to it.

Applies to

.NET 9 en andere versies
Product Versies
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0