private void OnCameHandler(Person p, int time)
        {
            Console.WriteLine($"{p.Name} came to office.");
            EveryoneSayHi?.Invoke(p, Person.TimeOfday);

            EveryoneSayHi  += p.SayHi;
            EveryoneSayBye += p.SayBye;
            Console.WriteLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            log4net.Config.BasicConfigurator.Configure();

            Rectangle rectangle = new Rectangle();

            log.Info("Area of Rectangle :: " + rectangle.GetArea(12.34, 56.78));
            log.Info("Perimeter of the Rectangle :: " + rectangle.GetPerimeter(12.34, 56.78));

            log.Info("Getting area and perimeter using delegates");
            RectDelegate rectDelegate = rectangle.GetArea;

            rectDelegate += rectangle.GetPerimeter;

            //This will be calling both the methods and execute both the methods, but the proble is..it will be showing last methods result because 1st method's result is being overwritten by last method.
            log.Info("Area and Perimeter using Delegate :: " + rectDelegate.Invoke(12.34, 56.78));

            //This is anonymous method delclaration using delegate.
            Greetings greetings = delegate(string Name)
            {
                return("Hello " + Name);
            };

            log.Info(greetings.Invoke("Ramesh"));

            //Lambda Expression using delegate
            greetings = (Name) =>
            {
                return("Hello " + Name + ",  have a nice day !!!");
            };
            log.Info(greetings.Invoke("Ramesh Khanna"));

            //Lambda method call
            List <int> list = rectangle.LambdaMethod();

            foreach (int number in list)
            {
                log.Info(number);
            }

            Console.Read();
        }
示例#3
0
        static void Main()
        {
            Greetings g = (name) =>
            {
                return("Hello " + name + " a well good ");
            };

            string str = g.Invoke("om ");

            Console.WriteLine(str);
            Console.ReadLine();
        }