예제 #1
0
        public static void Main1()
        {
            DT d = f1;

            //<=>
            //DT d = new DT(Del.f1);
            d(1);
            d.Invoke(1);

            //d = f2;
            d = new DT(Del.f2);
            d(2);

            //d = new Del().instance;
            Del p = new Del();

            d = p.instance;
            //d = new DT(p.instance);
            d(3);
            //p.instance(10); // E' possivel associar metodos privados a delegates mas so' e' possivel chama-los dentro da classe.

            d = new Test().instance;
            d(20);

            //d = error; // Error, void Del.error(int) has the wrong return type
            //////
            DT chain1 = f1;

            chain1 += f2;

            DT chain2 = p.instance;

            chain2 += f1;

            DT chain3 = chain1 + chain2;

            Console.WriteLine(chain3(100));
            Console.WriteLine(chain3.GetInvocationList().Length);
            chain3 -= f1;
            Console.WriteLine(chain3(100));
            Console.WriteLine(chain3.GetInvocationList().Length);
        }