public static void Main()
        {
            ///<summary>
            ///0. multicast delegates are delegates that has references to more than one function. When you invoke that one delegate, all of functions will
            ///be invoked
            ///</summary>

            //sampleDelegate del = new sampleDelegate(sampleMethod1); //1. in the parenthesis we put the function that we want the delegate to point to
            //del();
            //sampleDelegate del1, del2, del3, del4;
            //del1 = new sampleDelegate(sampleMethod1);
            //del2 = new sampleDelegate(sampleMethod2);
            //del3 = new sampleDelegate(sampleMethod3);

            //del4 = del1 + del2 + del3; //2. del4 now points to all 3 other delegates so when del4 is invoked, del1, del2, del3 are all invoked at once
            //del4();                    //to multicast delegates, just use the plus sign

            sampleDelegate del = new sampleDelegate(sampleMethod1);

            del += sampleMethod2; //3. we are using the single instance to call other methods
            del += sampleMethod3;

            del();

            sampleDelegateNumb delNumb = new sampleDelegateNumb(sampleMethodNumb1); //4. if the return type of delegate is anything other than void and

            //is a multicast delegate only the last invoked method will return
            delNumb += sampleMethodNumb2;

            int retrunDelNumb = delNumb();

            Console.WriteLine(retrunDelNumb);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //// mulitcast delegates
            //sampleDelegate del1, del2, del3, del4;

            //del1 = new sampleDelegate(sampleMethodOne);
            //del2 = new sampleDelegate(sampleMethodTwo);
            //del3 = new sampleDelegate(sampleMethodThree);
            //// multicast delegate
            //del4 = del1 + del2 + del3;
            //del4();

            sampleDelegate del = new sampleDelegate(sampleMethodOne);   // register sampleMethodOne to delegate

            del += sampleMethodTwo;                                     // register sampleMethodTwo to delegate
            del += sampleMethodThree;                                   // register sampleMethodThree to delegate
            del -= sampleMethodThree;                                   // un-register sampleMethodThree to delegate
            del();

            sampleDelegateINT delINT = new sampleDelegateINT(sampleMethodOneINT);

            delINT += sampleMethodTwoINT;
            Console.WriteLine("Returned Value {0}", delINT());

            sampleDelegateOUT delOUT = new sampleDelegateOUT(sampleMethod1);

            delOUT += sampleMethod2;
            int param;

            delOUT(out param);
            Console.WriteLine("Output Parameter Value : {0}", param);
            Console.ReadLine();
        }
Beispiel #3
0
        public static void Main( )
        {
            testDelegate   obj         = new testDelegate();
            sampleDelegate delegateObj = new sampleDelegate(obj.checkEven);

            delegateObj += new sampleDelegate(obj.squareNumber);
            delegateObj(25);
        }
        public static void Main(string[] args)
        {
            sampleDelegate mydelegate=delegate(int num){
                Console.WriteLine("this is an anonymous delegate method {0}",num);
            };
            mydelegate(99);

            mydelegate = new sampleDelegate (Method1);
            mydelegate(65);
        }
        public static void Main(string[] args)
        {
            sampleDelegate mydelegate = delegate(int num){
                Console.WriteLine("this is an anonymous delegate method {0}", num);
            };

            mydelegate(99);

            mydelegate = new sampleDelegate(Method1);
            mydelegate(65);
        }
        static void Main(string[] args)
        {
            int[] array = { 10, 12, 13, 14, 15 };

            List <int> a = new List <int>()
            {
                10, 20, 30, 40, 54, 23
            };
            var i = a.FindAll(x => (x % 2) == 0);

            foreach (var j in i)
            {
                Console.WriteLine(j);
            }
            sampleDelegate sample = (message) =>
            {
                Console.WriteLine("Hello " + message);
            };

            sample.Invoke("Madhu");
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            sampleDelegate del1, del2, del3, del4;

            del1 = new sampleDelegate(sampleMethod1);
            del2 = new sampleDelegate(sampleMethod2);
            del3 = new sampleDelegate(sampleMethod3);

            //multicast delegate.. point more than one function.
            // we can add and also subtract the delegate.
            //! method to create multicast D
            del4 = del1 + del2 + del3;
            del4();

            // 2 method for multi D
            sampleDelegate del = new sampleDelegate(sampleMethod1);

            del += sampleMethod2;
            del += sampleMethod3;
            del();
            Console.WriteLine("\n\n");

            // int return value it always return last invoked method val;
            SampleReturnDelegtae srd = new SampleReturnDelegtae(sampleReturn1);

            srd += sampleReturn2;
            int value = srd();

            Console.WriteLine(value);

            sampleoutDelegate sod = new sampleoutDelegate(sampleoutMethod1);

            sod += sampleoutMethod2;
            int result = 0;

            sod(out result);
            Console.WriteLine("value of last invoke method using out parameter in the result varibale is {0}", result);
        }