static void Main(string[] args) { #region 1.C Use delegate to de couple the logic of promoting the employee. List<Employee> empList = new List<Employee>(); empList.Add(new Employee() { ID = 101, Name = "Anand", Salary = 4000, Experience = 3 }); empList.Add(new Employee() { ID = 102, Name = "Praveen", Salary = 5000, Experience = 5 }); empList.Add(new Employee() { ID = 103, Name = "Anoop", Salary = 6000, Experience = 4 }); empList.Add(new Employee() { ID = 104, Name = "Uttam", Salary = 8000, Experience = 9 }); IsPromotable isProtable = new IsPromotable(Promote); Employee.PromoteEmployee(empList, isProtable); #endregion #region 2.B Use delegate and lamda expression while calling it. //// lamda expression is basically work on delegates. So we can remove the creating delegate object and creating the function. List<Customer> custList = new List<Customer>(); custList.Add(new Customer() { Name = "Ryan Lim", PurchaseAmount = 1000 }); custList.Add(new Customer() { Name = "Jimmy Leong", PurchaseAmount = 20000 }); custList.Add(new Customer() { Name = "Zech Lim", PurchaseAmount = 40000 }); custList.Add(new Customer() { Name = "John read", PurchaseAmount = 6000 }); // Here we are using lamda expression, for logic of valuable customer rather than creating a fucntion for delegate. Customer.IsValuableCustomer(custList, cust => cust.PurchaseAmount >= 10000); #endregion #region Example Voter v = new Voter(); v.Age = 20; v.LetsVote(v, voter => voter.Age >= 18); Example_1 ex = new Example_1(); ex.ExampleMethod(); #endregion Console.ReadKey(); }
public void LetsVote(Voter voterAge, IsVoteAble isVoteAble) { if (isVoteAble(voterAge)) { Console.WriteLine("You can vote.\n"); } else { Console.WriteLine("Please wait child.\n"); } }
static void Main(string[] args) { #region 1.C Use delegate to de couple the logic of promoting the employee. List <Employee> empList = new List <Employee>(); empList.Add(new Employee() { ID = 101, Name = "Anand", Salary = 4000, Experience = 3 }); empList.Add(new Employee() { ID = 102, Name = "Praveen", Salary = 5000, Experience = 5 }); empList.Add(new Employee() { ID = 103, Name = "Anoop", Salary = 6000, Experience = 4 }); empList.Add(new Employee() { ID = 104, Name = "Uttam", Salary = 8000, Experience = 9 }); IsPromotable isProtable = new IsPromotable(Promote); Employee.PromoteEmployee(empList, isProtable); #endregion #region 2.B Use delegate and lamda expression while calling it. //// lamda expression is basically work on delegates. So we can remove the creating delegate object and creating the function. List <Customer> custList = new List <Customer>(); custList.Add(new Customer() { Name = "Ryan Lim", PurchaseAmount = 1000 }); custList.Add(new Customer() { Name = "Jimmy Leong", PurchaseAmount = 20000 }); custList.Add(new Customer() { Name = "Zech Lim", PurchaseAmount = 40000 }); custList.Add(new Customer() { Name = "John read", PurchaseAmount = 6000 }); // Here we are using lamda expression, for logic of valuable customer rather than creating a fucntion for delegate. Customer.IsValuableCustomer(custList, cust => cust.PurchaseAmount >= 10000); #endregion #region Example Voter v = new Voter(); v.Age = 20; v.LetsVote(v, voter => voter.Age >= 18); Example_1 ex = new Example_1(); ex.ExampleMethod(); #endregion Console.ReadKey(); }