public static void Delegates() { HelloFunctionDelegate dele = new HelloFunctionDelegate(Delegate.hello); dele("Hello from INDIA"); List <Employee> empList = new List <Employee>(); empList.Add(new Employee { Name = "Marry", Id = 2, Experience = 5, Salary = 1202 }); empList.Add(new Employee { Name = "Henry", Id = 3, Experience = 3, Salary = 20502 }); empList.Add(new Employee { Name = "Deepak", Id = 4, Experience = 5, Salary = 125002 }); empList.Add(new Employee { Name = "Muthu", Id = 5, Experience = 1, Salary = 10002 }); IsPromotableDelegate promoteDele = new IsPromotableDelegate(PromoteBasedOnExp); Employee.PromoteEmployess(empList, promoteDele); /// OR Using Lambda Employee.PromoteEmployess(empList, emp => emp.Salary > 1000); }
static void Main(string[] args) { List <Employee> empList = new List <Employee>(); empList.Add(new Employee() { Id = 101, Name = "Mary", Salary = 5000, Experience = 5 }); empList.Add(new Employee() { Id = 101, Name = "John", Salary = 4000, Experience = 4 }); empList.Add(new Employee() { Id = 101, Name = "David", Salary = 3000, Experience = 6 }); empList.Add(new Employee() { Id = 101, Name = "Mike", Salary = 6000, Experience = 3 }); //Create instance of delegate IsPromotableDelegate promotable = new IsPromotableDelegate(IsPromotable); Employee thisEmployee = new Employee(); thisEmployee.PromoteEmployee(empList, employee => employee.Experience >= 5); }
public void PromoteEmployee(List <Employee> employeeList, IsPromotableDelegate Promote) { foreach (Employee employee in employeeList) { if (Promote(employee)) { Console.WriteLine($"{employee.Name} is promoted"); } } }
public static void PromoteEmployess(List <Employee> emplList, IsPromotableDelegate isPromotable) { foreach (Employee emp in emplList) { if (isPromotable(emp)) { Console.WriteLine(emp.Name + "is promoted"); } } }