Example #1
0
        public static void ProcessResult(IAsyncResult token)
        {
            funcBinary func = (funcBinary)token.AsyncState;

            int res = func.EndInvoke(token);

            Console.WriteLine(res);
        }
Example #2
0
        static int SquareUsingDelegateParameter(int x, int y, funcBinary binary)
        {
            int a = x * x;
            int b = y * y;

            int res = binary.Invoke(a, b);


            return(res);
        }
Example #3
0
        static void Main2(string[] args)
        {
            Myclass obj = new Myclass();

            funcBinary x = null;

            Random r   = new Random();
            int    num = r.Next(1, 6);

            switch (num)
            {
            case 1:
                //we are saving the function context inside the delegate variable
                x = new funcBinary(obj.add);    //upto .net 1.1
                break;

            case 2:
                x = obj.mul;
                break;

            case 3:
                x = obj.sub;
                break;

            case 4:
                x = obj.div;
                break;

            case 5:
                x = obj.powr;
                break;
            }

            //int res = x.Invoke(3, 4);
            //Console.WriteLine("result :" + res);
            x.BeginInvoke(3, 4, ProcessResult, x);

            Console.WriteLine("Continuing with the usual task....");

            Console.ReadKey();
        }