.NET Expression 从零开始三:运算符

本文介绍表达式中允许的运算符表达式,如一元、二元、三元运算符等等 会简易的提供几个运算应用的代码小示例 下面列出各个运算符表达式

一元运算符

!// Expression.Not(Expression.Constant(false));

~// Expression.Not(Expression.Constant(0));

++i// ParameterExpression i = Expression.Parameter(typeof(int), "i");
               Expression.PreIncrementAssign(i);

--i // ParameterExpression i = Expression.Parameter(typeof(int), "i");
               Expression.PreDecrementAssign(i);

i++// ParameterExpression i = Expression.Parameter(typeof(int), "i");

   Expression.PostIncrementAssign(i);

i--// ParameterExpression i = Expression.Parameter(typeof(int), "i");

               Expression.PostDecrementAssign(i);

二元运算符

+  // Expression.Add(Expression.Constant(1), Expression.Constant(2));

-  // Expression.Subtract(Expression.Constant(1), Expression.Constant(2));

* // Expression.Multiply(Expression.Constant(1), Expression.Constant(2));

/// Expression.Divide(Expression.Constant(1), Expression.Constant(2));

&// Expression.And(Expression.Constant(1), Expression.Constant(2)); 

|// Expression.Or(Expression.Constant(1), Expression.Constant(2));

^// Expression.ExclusiveOr(Expression.Constant(1), Expression.Constant(2)); // XOR

&&// Expression.AndAlso(Expression.Constant(true), Expression.Constant(false));

||// Expression.OrElse(Expression.Constant(true), Expression.Constant(false));

>>// Expression.RightShift(Expression.Constant(32), Expression.Constant(1));

<<// Expression.LeftShift(Expression.Constant(32), Expression.Constant(1));

+=// ParameterExpression i = Expression.Parameter(typeof(int), "i");

    Expression.AddAssign(i, Expression.Constant(1));

-=// ParameterExpression i = Expression.Parameter(typeof(int), "i");

   Expression.SubtractAssign(i, Expression.Constant(1));

|=// ParameterExpression i = Expression.Parameter(typeof(int), "i");

   Expression.OrAssign(i, Expression.Constant(1));

^=// ParameterExpression i = Expression.Parameter(typeof(int), "i"); 

   Expression.ExclusiveOrAssign(i, Expression.Constant(1));

&=// ParameterExpression i = Expression.Parameter(typeof(int), "i");

   Expression.AndAssign(i, Expression.Constant(1));

>>=  // ParameterExpression i = Expression.Parameter(typeof(int), "i"); 

   Expression.RightShiftAssign(i, Expression.Constant(1));

<<=  // ParameterExpression i = Expression.Parameter(typeof(int), "i"); 

   Expression.LeftShiftAssign(i, Expression.Constant(1));

< // Expression.LessThan(Expression.Constant(0), Expression.Constant(1));

<=  // Expression.LessThanOrEqual(Expression.Constant(0), Expression.Constant(1));

> // Expression.GreaterThan(Expression.Constant(0), Expression.Constant(1));

>= // Expression.GreaterThanOrEqual(Expression.Constant(0), Expression.Constant(1));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值