• λ我爱Aspx >> C#.Net >> C# 3.0新特性初步研究 Part3:使用拉姆达表达式_C#教程
  • C# 3.0新特性初步研究 Part3:使用拉姆达表达式_C#教程

  • :aspxer  Դ:internet  :2007-4-28 20:57:58  ؼ:c#
  • 这里还有一个有趣的东西:Lambda Expression Tree(拉姆达表达式树)

    这是一种用来在运行时把表达式作为数据的技术,我们可在运行时灵活的控制和改变表达式,

    增强程序的灵活性!

    还是看代码吧,这样直接一点:

    1using System.Expressions;

    2

    3static void Main(string[] args)

    4{

    5 Expression<Func<int, bool>> filter = n => (n * 3) < 5;

    6

    7 BinaryExpression lt = (BinaryExpression) filter.Body;

    8 BinaryExpression mult = (BinaryExpression) lt.Left;

    9 ParameterExpression en = (ParameterExpression) mult.Left;

    10 ConstantExpression three = (ConstantExpression) mult.Right;

    11 ConstantExpression five = (ConstantExpression) lt.Right;

    12

    13 Console.WriteLine("({0} ({1} {2} {3}) {4})", lt.NodeType,

    14 mult.NodeType, en.Name, three.Value, five.Value);

    15}

    输出:

    (LT (Multiply n 3) 5)

    通过这种技术,我们对于数据和数据表达式的操作可以变得更加轻松,不用动不动就是写方法了。

    http://zc1984.cnblogs.com/archive/2006/06/10/422679.html

    Ҷƪл˵?
  • һƪC# 3.0新特性初步研究 Part2:使用扩展方法_C#教程
    һƪC# 3.0新特性初步研究 Part4:使用集合类型初始化器_C#教程