Multicast Delegate

Multicast Delegate

///-------------------understading Delegate //mutlicastDelegate -----------------------///
    class multicastdelegate
    {
        delegate string function1(string display);
        static function1 fun = getMessage;

        static string getMessage(string display)
        {
            return display + " this is Multicast delegate from getMessage";
        }

        static string getMessage2(string display)
        {
            return display + " this is Multicast delegate from getMessage2";
        }

        static string getMessage3(string display)
        {
            return display + " this is Multicast delegate from getMessage3";
        }

        public static void Main()
        {
            string t = fun.Invoke("Hello");
            Console.WriteLine(t);

            //1st way of muticasting a delegate of 2nd form
            fun += getMessage2;
            string t2 = fun.Invoke("Hello");
            Console.WriteLine(t2);

            //2nd way of invocation of the delegate of 2nd form
            fun += new function1(getMessage2);
            string t4 = fun("Hello");


            fun += getMessage3;
            string t3 = fun.Invoke("Hello");
            Console.WriteLine(t3);

            Console.ReadLine();

        }

    }

Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6