Lambda基础例子

来源:互联网 发布:jquery.form.js用法 编辑:程序博客网 时间:2024/06/06 16:48
    class Program
    {
        delegate int del(int i);


        static void Main(string[] args)
        {


            //List<string> list = new List<string> { "田三涛", "刘起涵", "张晓轩", "田圣彤", "文筠彤", "刘起涵", "田优乔", "文嘉珊", "白田彤", "廖子棉", "张泽菲", "田赞鑫" };
            //C#1.0
            //List<string> result = list.FindAll(IsMatch);
            //C#2.0
            //List<string> result = list.FindAll(delegate(string s)
            // {
            //     return s.IndexOf("田") == 0;
            // });
            //C#3.0
            //List<string> result = list.FindAll(s => s.IndexOf("田") == 0);


            //foreach (var item in result)
            //{
            //    Console.WriteLine(item);
            //}


            //Console.ReadLine();
            del myDelegate = x => x * x;
            int j = myDelegate(5); //j = 25
            Console.WriteLine(myDelegate);
            Console.WriteLine(j);
            Console.ReadLine();
        }


        //public static bool IsMatch(string s)
        //{


        //    return s.IndexOf("田") == 0;


        //}
    }
    
原创粉丝点击