现在的位置: 首页 > 综合 > 正文

关于lambda的定义

2011年05月21日 ⁄ 综合 ⁄ 共 665字 ⁄ 字号 评论关闭
一直误解为lambda是通过编译器+System.Core.Func<T,T>等结合而成的,
其实不是只要你定义的委托符合要求就使用相关功能,就是说这功能是完全编译器支持你可以使用此项功能来编写代码最终生成完全基于2.0的应用程序。

    class Program
    
{
        
static void Main(string[] args)
        
{
            User user 
= new User();
            user.List(p 
=> p.Name == "henry");
            Console.Read();
          
        }

    }

    
public delegate TResult MyFunc<T,TResult>(T e);
    
public class User
    
{
        
public string Name
        
{
            
get;
            
set;
        }

        
public DateTime BirthDate
        
{
            
get;
            
set;
        }

        
public void List(MyFunc<User, bool> exp)
        
{
            Console.WriteLine(exp(
this));
        }

    }

抱歉!评论已关闭.