Exemplo n.º 1
0
        internal void Call()
        {
            NumberChangerDelegate ncAdd  = new NumberChangerDelegate(AddNum);
            NumberChangerDelegate ncMult = new NumberChangerDelegate(MultNum);
            NumberGetDelegate     nGet   = new NumberGetDelegate(GetNum);

            //calling the methods using the delegate objects
            ncAdd(25);
            Console.WriteLine("add 10 + '25': {0}", nGet());
            ncMult(5);
            Console.WriteLine("multi 15 * '5': {0}", nGet());
        }
Exemplo n.º 2
0
        internal void Call()
        {
            NumberChangerDelegate ncDel;
            NumberChangerDelegate ncAdd  = new NumberChangerDelegate(AddNum);
            NumberChangerDelegate ncMult = new NumberChangerDelegate(MultNum);
            NumberGetDelegate     nGet   = new NumberGetDelegate(GetNum);

            ncDel = ncAdd + ncMult;
            ncDel(5);

            Console.WriteLine("add then multiply (10 + '5')'5': {0}", nGet());

            ncDel = ncAdd + ncMult - ncAdd;
            ncDel(2);
            Console.WriteLine("add then multiply (75 + '2')'2' but we remove addition. so 75 * 2: {0}", nGet());
        }