Exemple #1
0
        static void Main(string[] args)
        {
            //静态方法,注意委托没有空构造方法
            //PrintHelloWorld Hello1 = new PrintHelloWorld();       //不对
            //PrintHelloWorld Hello1 = new PrintHelloWorld(null);   //不对
            PrintHelloWorld Hello1 = new PrintHelloWorld(SayHello);

            Program pg = new Program();

            pg.Name = "Instance Method";
            //实例方法
            PrintHelloWorld Hello2 = new PrintHelloWorld(pg.InstanceSayHello);

            //委托组合1
            PrintHelloWorld Hello3 = Hello1 + Hello2;

            //委托组合2: 使用+= -=
            Hello1 += Hello2;
            Hello1 -= Hello2;

            //委托组合3: 直接加方法签名   //!!!!!!!!!!!!!!!!
            Hello1 += SayHello;

            //自定义事件的使用
            TestEvent Test = new TestEvent();

            Test.SelfDefineEvent += pg.TestEventSelfEventRaised;
            Test.RaiseEvent();

            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
        // GET api/values
        public string Get()
        {
            //return new string[] { "value1", "value2" };

            PrintHelloWorld words = new PrintHelloWorld();

            return(words.PrintHello());
        }