static void Main(string[] args) { //var del1= new WorkPerformedHandler(WorkPerformed1); //var del2= new WorkPerformedHandler(WorkPerformed2); //var del3= new WorkPerformedHandler(WorkPerformed3); //del1(5, WorkType.Golf); //del2(10, WorkType.GotToMettings); /* inovkation list of multicast del1 += del2; del1 += del3; */ /* shortcut for invokation list multicast del1 += del2 + del3; */ //del1(10, WorkType.Golf); //DoWork(del2); var worker = new Worker(); //worker.WorkPerformed += Worker_WorkPerformed; //worker.WorkCompleted += Worker_WorkCompleted; //same as the above using lambda expression worker.WorkPerformed += (s,e)=>Console.WriteLine("Hours"+ e.Hours +"WorkType "+e.WorkType); worker.WorkCompleted += (s,e)=>Console.WriteLine("Work completed"); worker.DoWork(10,WorkType.GeneratingReports); Console.Read(); }
static void Main(string[] args) { //var del1= new WorkPerformedHandler(WorkPerformed1); //var del2= new WorkPerformedHandler(WorkPerformed2); //var del3= new WorkPerformedHandler(WorkPerformed3); //del1(5, WorkType.Golf); //del2(10, WorkType.GotToMettings); /* inovkation list of multicast * del1 += del2; * del1 += del3; */ /* shortcut for invokation list multicast * del1 += del2 + del3; */ //del1(10, WorkType.Golf); //DoWork(del2); var worker = new Worker(); //worker.WorkPerformed += Worker_WorkPerformed; //worker.WorkCompleted += Worker_WorkCompleted; //same as the above using lambda expression worker.WorkPerformed += (s, e) => Console.WriteLine("Hours" + e.Hours + "WorkType " + e.WorkType); worker.WorkCompleted += (s, e) => Console.WriteLine("Work completed"); worker.DoWork(10, WorkType.GeneratingReports); Console.Read(); }
static void Main(string[] args) { var custs = new List <Customer> { new Customer { FirstName = "Simhachalam", LastName = "Chintalapudi", Id = 1, City = "Tanuku" }, new Customer { FirstName = "Annavaram", LastName = "Meruduri", Id = 2, City = "Atthili" }, new Customer { FirstName = "Tirupati", LastName = "Tottempudi", Id = 3, City = "Ramvaram" }, new Customer { FirstName = "Bhadrachalam", LastName = "Relangi", Id = 4, City = "Tanuku" } }; var Tancusts = custs.Where(c => c.City == "Tanuku"); foreach (var item in Tancusts) { Console.WriteLine(item.FirstName + "-" + item.City); } var worker = new Worker(); // worker.WorkPerformed += new EventHandler<WorkPerformedEventArgs>(Worker_WorkPerformed); // worker.WorkPerformed += Worker_WorkPerformed; ///* Anonymous method call*/ worker.WorkPerformed += delegate (object sender, WorkPerformedEventArgs e) // { // Console.WriteLine("Hours worked :" + e.Hours + " " + e.workType.ToString()); // }; /*Lambda Expression*/ worker.WorkPerformed += (s, e) => { Console.WriteLine("Hours worked :" + e.Hours + " " + e.workType.ToString()); }; worker.WorkCompleted += (s, e) => Console.WriteLine("Work completed"); /* Custom delegate*/ BizRulesDelegate addDel = (x, y) => x + y; BizRulesDelegate mulDel = (x, y) => x * y; var data = new ProcessData(); data.Process(5, 6, addDel); /*Action*/ Action <int, int> myaction = (x, y) => Console.WriteLine(x / y); data.ProcessAction(56, 6, myaction); /* Func */ Func <int, int, int> myAddFunc = (x, y) => x + y; data.ProcessFunc(5, 7, myAddFunc); // worker.WorkCompleted += Worker_WorkCompleted; worker.DoWork(7, WorkType.Cool); Console.Read(); }