Example #1
0
        public static void Main(string[] args)
        {
            WorkerIsWorking       += (s, e) => Console.WriteLine($"Working for {e.WorkingHours} hours..\n");
            WorkerIsWorking       += WantMessage;
            WorkerFinishedWorking += WorkingFinishMessage;
            DoWork(5, "No complaint!");
            unchecked
            {
            }
            Action <int, int> add = (x, y) => Console.WriteLine(x + y);
            var processor         = new ProcessData();

            processor.Process(5, 3, add);


            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            var customers = new List <Customer> {
                new Customer {
                    ID = 1, LastName = "lastclient1", FirstName = "firstclient1", City = "cityclient1"
                },
                new Customer {
                    ID = 2, LastName = "lastclient2", FirstName = "firstclient2", City = "cityclient1"
                },
                new Customer {
                    ID = 3, LastName = "lastclient3", FirstName = "firstclient3", City = "cityclient2"
                },
                new Customer {
                    ID = 4, LastName = "lastclient4", FirstName = "firstclient4", City = "cityclient3"
                }
            };

            var cityCust = customers.Where(c => c.City == "cityclient1" && c.ID < 2).OrderBy(c => c.FirstName);

            foreach (var cust in cityCust)
            {
                Console.WriteLine(cust.FirstName);
            }

            Console.WriteLine("************************************************************");

            BizRuleDelegate addDel = (x, y) => x + y;

            var process = new ProcessData();

            process.Process(3, 8, addDel);
            Action <int, int> myAction = (x, y) => Console.WriteLine("Action lambda in: " + (x + y));

            process.ProcessAction(2, 3, myAction);

            Func <int, int, int> funcAddDel = (x, y) => x + y;

            process.ProcessFunc(2, 4, funcAddDel);

            Console.WriteLine("************************************************************");

            WorkPerformedHandler del1 = new WorkPerformedHandler(WorkPerformed1);
            WorkPerformedHandler del2 = new WorkPerformedHandler(WorkPerformed2);
            WorkPerformedHandler del3 = new WorkPerformedHandler(WorkPerformed3);

            del1(4, WorkType.Golf);
            del2(10, WorkType.GeneralReports);
            DoWork(del1);

            del1 += del2 + del3;
            int finalHours = del1(4, WorkType.Golf);// last value returned

            Console.WriteLine(finalHours);

            Console.WriteLine("************************************************************");

            var worker = new Worker();

            worker.WorkPerformed  += new WorkPerformedHandler(WorkPerformed1);
            worker.WorkPerformed2 += (s, e) => Console.WriteLine("1 line lambda worked: " + e.Hours + " " + e.WorkType);
            worker.WorkPerformed2 += new WorkPerformedHandler2(Worker_WorkPerformed);
            worker.WorkPerformed3 += new EventHandler <WorkPerformedEventArgs>(Worker_WorkPerformed);
            worker.WorkPerformed3 += autogenerated_Worker_WorkPerformed;
            worker.WorkPerformed3 += delegate(object sender, WorkPerformedEventArgs e)
            {
                Console.WriteLine("Anonymouse worked: " + e.Hours + " " + e.WorkType);
            };

            worker.WorkCompleted  += new WorkCompletedHandler(Worker_WorkComleted);
            worker.WorkCompleted2 += (s, e) =>
            {
                Console.WriteLine("1) two line lambda");
                Console.WriteLine("2) Worker_WorkComleted");
            };
            worker.WorkCompleted2 += new EventHandler(Worker_WorkComleted);
            worker.WorkCompleted2 += autogenerated_Worker_WorkComleted;

            worker.DoWork(8, WorkType.GeneralReports);
        }