首页 > 代码库 > delegate委托

delegate委托

 public delegate void Del();
    public delegate string DelStr(string name);
    class Program
    {
        static string Name = string.Empty;
        static void Main(string[] args)
        {
            //Del del = Test;
            //Del del = delegate() { };
            //=>goes to 去执行
            //Del del = () => { };
            //DelStr del = Demo;
            //DelStr del = delegate(string name) { return name; };
            DelStr del2 = (name) => { Name = name; return Name; };
            Demo("张三", del2);
            Console.ReadKey();
        }
        static void Test() { }
        static void Demo(string name,DelStr del) {
            del(name);
            Console.WriteLine(Name);
        }
    }

 

delegate委托