首页 > 其他 > 详细

Expression小案例

时间:2021-08-22 18:56:31      阅读:27      评论:0      收藏:0      [点我收藏+]
技术分享图片

 

 


 

 





using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace _Console { public static class ExpressionTest { //Expression<Func<string, bool>> f = s => s.Length < 5; public static void Test() { ParameterExpression p = Expression.Parameter(typeof(string), "s"); MemberExpression stringLength = Expression.Property(p, "Length"); ConstantExpression five = Expression.Constant(5); BinaryExpression comparison = Expression.LessThan(stringLength, five); Expression<Func<string, bool>> lambda = Expression.Lambda<Func<string, bool>>(comparison, p); //end /* 将lambda编译为委托 Func<string, bool> runnable = lambda.Compile(); Console.WriteLine(runnable("kangaroo")); Console.WriteLine(runnable("dog")); */ } } }

  

Expression小案例

原文:https://www.cnblogs.com/SHa-Jazy/p/15172182.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!