委托的几个实例用法

class Program
    {
        private delegate void deleFunc(string str);
        static void Main(string[] args)
        {
            deleFunc func = new Program().Chinese;
            //func("张三");
            func += English;
            func("alex");

            Console.WriteLine( "==================");

            //匿名委托
            deleFunc func1 = delegate(string name)
                                 {
                                     Console.WriteLine("你好,{0}", name);
                                 };
            func1("李四");

            Console.WriteLine("==================");

            //lambda
            deleFunc func2 = (name => { Console.WriteLine("Hello, {0}", name); });
            func2("Jack");

            //action
            Console.WriteLine("==================");
            Action<string> acFun = (m => { Console.WriteLine("您好,{0}", m); });
            acFun("中国人");

            Func<stringstring> funcDelegate = (m => { return string.Format("Hello,{0}", m); });
            string result = funcDelegate("chinese man");
            Console.WriteLine(result);
           

            //实例应用

            int[] i = { 184515681266 };


            Func<intbool> foo = temp_i => temp_i > 10;
            var list = i.Where(foo);
            foreach (int i1 in list)
            {
                Console.WriteLine(i1);
            }
            Console.WriteLine("==================");

            i.Where(m => m > 15).ToList().ForEach(
                s => { Console.WriteLine(s); }
                );


            Console.Read();

        }

        private void Chinese(string name)
        {
            Console.WriteLine("你好:{0}",name);
        }

        private static void English(string name)
        {
            Console.WriteLine("Hello, {0}",name);
        }
    }
posted @ 2012-02-29 11:05  Aleax  阅读(319)  评论(0编辑  收藏  举报