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

            // 3- Passing the handling method to the delegate
            TestDelegateHandler testDelegateHandler  = new TestDelegateHandler(TestMethod1);
            TestDelegateHandler testDelegateHandler2 = new TestDelegateHandler(TestMethod2);

            // 4- Invoking the delegate
            DoWork(testDelegateHandler);
            DoWork(testDelegateHandler2);

            Console.Read();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Thread t = new Thread(new ThreadStart(getAsync));

            t.Start();
            //Task
            //getAsync();


            //Delegates example
            TestDelegateHandler delegate1 = new TestDelegateHandler(TestDelegateToFunction);
            TestDelegateHandler delegate2 = new TestDelegateHandler(TestDelegateToFunction2);

            Console.WriteLine("Call delegates");
            delegate1(5);  //Call TestDelegateToFunction through delete 1
            delegate2(10); //Call TestDelegateToFunction2 through delete 2
            Console.WriteLine("");


            Console.WriteLine("Call multiple delegates");
            //Call TestDelegateToFunction and TestDelegateToFunction2 through delete 1 (Deep is using an invocation list)
            delegate1 += delegate2; //Multiple delegates

            delegate1(15);

            //NOTE: If using return values with multiple deletes only the last delegate return value is returned
            Console.WriteLine("-----------------------------------------");

            for (int i = 0; i < 10; i++)
            {
                Console.Write("Write name: ");
                String name = Console.ReadLine();
                InsertAsync(name);
            }


            Console.ReadKey();
        }
 public static void DoWork(TestDelegateHandler testDelegateHandler)
 {
     testDelegateHandler(14, "Thiery Henry!");
     testDelegateHandler(34, "Granit Xhaka!");
 }