Lambda表达式

   //1,定义委托
        private delegate void MyDelegate(string name);

        // 2,这是我们欲传递的方法,它与MyDelegate具有相同的参数和返回值类型
        public static void MyDelegateMethod(string name)
        {
            Console.WriteLine("Hello,{0}", name);
        }

        static void Main(string[] args)
        {
            #region 委托
            //// 3,创建delegate对象
            //MyDelegate md = new MyDelegate(MyDelegateMethod);
            //// 4,调用delegate
            //md("Michael");
            #endregion

            #region 匿名方法
            //MyDelegate md = delegate(string name)
            //{
            //    Console.WriteLine("Hello,{0}", name);
            //};
            //md("Michael");

            #endregion

            #region Lambda表达式
            ////匿名委托
            //MyDelegate myDelegate =(name => Console.WriteLine("Hello,{0}", name));

            ////调用委托
            //myDelegate("Michael");

 

            #endregion
        }

posted @ 2015-03-23 22:17  914556495  阅读(125)  评论(0编辑  收藏  举报