Beispiel #1
0
        /// <summary>
        /// invoke the method with the help of delegate
        /// </summary>
        public void useDelegate()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(GenericDelegate));
            log.Info("Delegate is used for invoking the method");
            DelegeteDemo obj = new DelegeteDemo();
            addDelegete  ad  = new addDelegete(obj.addNums);

            ad.Invoke(125, 50);

            sayDelegete sd  = new sayDelegete(DelegeteDemo.sayHello);
            string      str = sd.Invoke("Atish chandra");

            Console.WriteLine(str);
        }
Beispiel #2
0
        /// <summary>
        /// we use Lambda Expresition in delegates
        /// </summary>
        public void useDelegateLambdaExp()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(GenericDelegate));
            log.Info("delegate use with the help of Lambda Expression ");
            addDelegete ad = (int x, int y) =>
            {
                Console.WriteLine("Additon of two no= " + (x + y));
            };

            ad.Invoke(10, 50);

            sayDelegete sd = (string name) =>
            {
                return("Hello" + " " + name);
            };

            string str = sd.Invoke("Gautan raj");

            Console.WriteLine(str);
        }
Beispiel #3
0
        /// <summary>
        /// we use Anonymous method  through delegate
        /// </summary>
        public void useAnonymousDelegate()
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(GenericDelegate));
            log.Info("delegate use with the help of  Anonymous class ");
            addDelegete ad = delegate(int x, int y)
            {
                Console.WriteLine("Additon of two no= " + (x + y));
            };

            ad.Invoke(125, 50);

            sayDelegete sd = delegate(string name)
            {
                return("Hello" + " " + name);
            };

            string str = sd.Invoke("Scott raj");

            Console.WriteLine(str);
        }