using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01匿名方法
{
    class Program
    {
        delegate void speak();
        static void Main(string[] args)
        {
            speak Speak = delegate { Console.WriteLine("你好小清"); };
            Action act = () => Console.WriteLine("你好冬清");//Lambda表达式
            Speak();
            act();
            Action Speaks = delegate { Console.WriteLine("清"); };
            Speaks();
            //声明匿名方法和正常方法一样,只不过需要写对委托
            Action<string> spe = delegate (string str) { Console.WriteLine("你好" + str); };
            Action<string> spr = (string srp) => Console.WriteLine("你好" + srp);
            spe("小清");
            spr("清");
            Func<int, int,int> Add = delegate (int i, int j) { return i + j; };
            //当lambda表达式中只有一条语句可以省略大括号
            Func<int, int> func = (int j) => j++;
            Console.WriteLine(func(4));
            Console.WriteLine(Add(22, 21));
            Console.ReadLine();
        }
    }
}
posted on 2019-02-06 15:31  豆皮没有豆  阅读(100)  评论(0)    收藏  举报