示例#1
0
        static void Main()
        {
            Sample s = new Sample();

            delcal del1 = new delcal(s.square);
            delcal del2 = new delcal(s.cube);
            delcal del  = del1 + del2;
            //del -= del2; will remove cube and only give square
            int f = del(5); //this will give the most recent delegate

            Console.WriteLine($"After returning {f}");
            Console.ReadLine();
        }
示例#2
0
        public static void Main()
        {
            sample s   = new sample();
            delcal dc1 = new delcal(s.Square);
            delcal dc2 = new delcal(s.triple);
            delcal dcall;

            dcall = dc2 + dc1;//multicast delegates +=/ -= /+ /-
            int result = dcall(5);

            Console.WriteLine(result);
            Console.Read();
        }
示例#3
0
        public static void Main(string[] args)
        {
            sample s   = new sample();
            delcal dc1 = new delcal(s.Square);
            delcal dc2 = new delcal(s.triple);
            delcal dcall;

            dcall = dc1 + dc2; //multicast delegates

            int result = dcall(5);

            Console.WriteLine(result); //multicast retains only last called delegate ie. it retained only dc2 when dc1+dc2 is called


            Console.ReadKey();
        }