Example #1
0
        static void Main(string[] args)
        {
            someDelegate myDelegate = new someDelegate(sum);
            int          x          = myDelegate(1, 1);

            Console.WriteLine(x);
        }
Example #2
0
        static void Main(string[] args)
        {
            Func <int, int, int> f          = sum;
            someDelegate         myDelegate = new someDelegate(sum); // = sum; אפשר גם

            myDelegate += delegate(int x, int y) { return(x * y); }; // mult; //
            myDelegate += (x, y) => x - y;                           // sub; //
            myDelegate -= sum;

            foreach (someDelegate d in myDelegate.GetInvocationList())
            {
                Console.WriteLine(d.Method);
            }

            if (myDelegate is Delegate)
            {
                Console.WriteLine("myDelegate is Delegate == true");
            }

            //myDelegate.Invoke(1, 1);
            //זה מפעיל את כל הפונקציות שבדלגט, עם ובלי הפונקציה

            foreach (someDelegate item in myDelegate.GetInvocationList())
            {
                Console.WriteLine(item(3, 2));
            }
            /// הלולאה נחוצה על מנת להדפיס
            /// -  ביצוע הפוקנציות נעשה בכל הפעלה של הדלגט,
            /// אבל להדפסה תופעל רק הפעולה האחרונה
            Console.WriteLine("Now let's invoke all and print:");
            Console.WriteLine(myDelegate(3, 2));
        }
Example #3
0
        static void Main(string[] args)
        {
            someDelegate myDelegate = new someDelegate(sum); // = sum; אפשר גם

            myDelegate += mult;

            foreach (someDelegate d in myDelegate.GetInvocationList())
            {
                Console.WriteLine(d.Method);
            }

            if (myDelegate is Delegate)
            {
                Console.WriteLine("myDelegate is Delegate == true");
            }

            Console.WriteLine(myDelegate(1, 1));
            //myDelegate.Invoke(1, 1);
            //זה מפעיל את כל הפונקציות שבדלגט, עם ובלי הפונקציה

            //foreach (someDelegate item in myDelegate.GetInvocationList())
            //    Console.WriteLine(item.Invoke(1, 1));
            /// הלולאה נחוצה על מנת להדפיס
            /// -  ביצוע הפוקנציות נעשה בכל הפעלה של הדלגט,
            /// אבל להדפסה תופעל רק הפעולה האחרונה
        }
Example #4
0
        static void Main(string[] args)
        {
            someDelegate myDelegate = sum;

            myDelegate += mult;
            myDelegate -= sum;
            foreach (Delegate d in myDelegate.GetInvocationList())
            {
                Console.WriteLine(d.Method);
            }
        }
Example #5
0
        public static void ExecuteMain()
        {
            someDelegate sd = SquareNumber;

            Console.WriteLine("Before SquareNumber method invoke.");
            IAsyncResult asynRes = sd.BeginInvoke(10, null, null);

            Console.WriteLine("After SquareNumber invoked.");
            int res = sd.EndInvoke(asynRes);

            Console.WriteLine(res);
            Console.ReadLine();
        }
Example #6
0
        static void Main(string[] args)
        {
            someDelegate myDelegate = new someDelegate(sum);

            myDelegate += mult;

            foreach (someDelegate d in myDelegate.GetInvocationList())
            {
                Console.WriteLine(d.Method);
            }

            if (myDelegate is Delegate)
            {
                Console.WriteLine("myDelegate is Delegate == true");
            }

            foreach (someDelegate item in myDelegate.GetInvocationList())
            {
                Console.WriteLine(item(1, 1));
            }
        }
Example #7
0
        public DelegateExample(TextBox tb_delegate)
        {
            this.tb_delegate = tb_delegate;
            someDelegate myDlgt = new someDelegate(sum);

            myDlgt          += mult;
            myDlgt          += sub;
            myDlgt          -= sum;
            tb_delegate.Text = "";
            foreach (var d in myDlgt.GetInvocationList())
            {
                tb_delegate.Text += d.Method.Name + "\n";
            }
            if (myDlgt is Delegate)
            {
                tb_delegate.Text += "myDlgt is Delegate == true";
            }
            tb_delegate.Text += "\n";
            // tb_delegate.Text += myDlgt(3, 2);
            foreach (someDelegate item in myDlgt.GetInvocationList())
            {
                tb_delegate.Text += item(3, 2) + "\n";
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            someDelegate myDelegate = (x, y) => x + y;

            Console.WriteLine(myDelegate(1, 1));
        }
 public static void callFunction(int i, someDelegate del)
 {
     del.Invoke(i);
 }