Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");


            /*
             * Passing functions as parameters: Delegates essentially act as pointers towards
             *  functions. It's a reference data type that holds the reference of a method.
             *
             * They can be declared using the *delegate* keyword.
             *
             * Here's an example.
             *
             */


            delegatePrint printDel = PrintNumber;

            printDel(1000);

            printDel = PrintMoney;

            printDel(1000);


            Console.ReadLine();
        }
Exemple #2
0
        public static void DelFunc()
        {
            // del is a multicast delegate, since it is pointing to multiple methods
            // methods are called in the same order in which they are referenced
            delegatePrint del = new delegatePrint(print1);

            del += print2;
            del += print3;
            del -= print2;
            del();
        }
Exemple #3
0
 public void Print(string s)
 {
     if (InvokeRequired)
     {
         delegatePrint d = new delegatePrint(Print);
         //d.Invoke(s);
         this.Invoke(d, new object[] { s });
     }
     else
     {
         richTextBoxLogger.Text          += s + "\r\n";
         richTextBoxLogger.SelectionStart = richTextBoxLogger.TextLength;
         richTextBoxLogger.ScrollToCaret();
     }
 }