Esempio n. 1
0
        public static void Run()
        {
            NamedActionDelegate = NamedMethod;
            NamedActionDelegate?.Invoke("Hi", 5);

            AnonymousActionDelegate?.Invoke("Hi", 5);
        }
Esempio n. 2
0
        // A callback is a function that will be called when a process is done executing
        // a specific task
        public static void Run()
        {
            // To create a callback, a function address needs to be stored in a variable
            WorkCompletedCallBack callBack = TestCallBack;

            DoWork(callBack);

            DoMoreWork(Console.WriteLine);

            // Delegates (see below)
            // ------------------------------------------------------
            Foo fooExample = Bar;
            var time       = fooExample(DateTime.UtcNow);

            Console.WriteLine(time);

            // Action delegate (see below)
            // ------------------------------------------------------
            // Named method
            NamedActionDelegate = NamedMethod;
            NamedActionDelegate?.Invoke("Named Action Delegate", 5);

            // Anonymous function
            AnonymousActionDelegate?.Invoke("Anonymous Action Delegate", 106);

            // Func delegate (see below)
            // ------------------------------------------------------
            NamedFuncDelegate = NamedMethod;
            var namedResult = NamedFuncDelegate?.Invoke(100);

            Console.WriteLine(namedResult);
        }