示例#1
0
        public static void Main(string[] args)
        {
            HelloFunctionDelegate del = new HelloFunctionDelegate(Hello);

            del("Hello from Delegate");

            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 = "Mike", Salary = 4000, Experience = 4
            });
            emplist.Add(new Employee()
            {
                ID = 101, Name = "John", Salary = 6000, Experience = 6
            });
            emplist.Add(new Employee()
            {
                ID = 101, Name = "Todd", Salary = 3000, Experience = 3
            });

            isPromotable ispromotable = new isPromotable(Promote);

            Employee.PromoteEmployee(emplist, ispromotable);

            // or use lamba expression

            Employee.PromoteEmployee(emplist, emp => emp.Experience >= 5);
        }
示例#2
0
        public static void Main()
        {
            List <Employee> empList = new List <Employee>();

            empList.Add(new Employee()
            {
                ID = 101, name = "Mary", salary = 5000, experience = 5
            });
            empList.Add(new Employee()
            {
                ID = 102, name = "Mike", salary = 4000, experience = 4
            });
            empList.Add(new Employee()
            {
                ID = 103, name = "Jack", salary = 6000, experience = 6
            });
            empList.Add(new Employee()
            {
                ID = 104, name = "Ron", salary = 3000, experience = 3
            });

            //1.a Employee.promoteEmp(empList);
            isPromotable isPromotable = new isPromotable(Promote);

            Employee.promoteEmp(empList, isPromotable);

            //this is a lambda expression. what this does is behind the scenes it creates a delegate, a function that has the same signature,
            //then passes it to the function below. this will get rid of the line "isPromotable ..." above.
            //Employee.promoteEmp(empList, emp => emp.experience >= 5);
        }
示例#3
0
 public static void promoteEmployee(List <Employee> list, isPromotable isEligible)
 {
     foreach (Employee emp in list)
     {
         if (isEligible(emp))
         {
             Console.WriteLine($"{emp.Name} is Eligible for promotion");
         }
     }
 }
示例#4
0
 public static void PromoteEmployee(List <Employee> employeeList, isPromotable IsEligibleToPromote)
 {
     foreach (Employee employee in employeeList)
     {
         if (IsEligibleToPromote(employee))
         {
             Console.WriteLine(employee.Name + " promoted");
         }
     }
 }
示例#5
0
 public void PromoteEmployee(List <Employee> empList, isPromotable forPromotion)
 {
     foreach (Employee emp in empList)
     {
         if (forPromotion(emp))
         {
             Console.WriteLine("Promoted");
         }
     }
 }
 public static void IsEmployeePromatable(List <Employee> employees, isPromotable isPromotable)
 {
     foreach (Employee emp in employees)
     {
         if (isPromotable(emp))
         {
             Console.WriteLine(emp.Name + "Promoted!");
         }
     }
 }
示例#7
0
 public void PromoteEmployees(list <Employee> EmployeeList, isPromotable Iseligible)
 {
     foreach (Employee employee in EmployeeList)
     {
         if (employee.Expirience >= 5)
         {
             Console.WriteLine(employee.Name + " Promoted");
         }
     }
 }
示例#8
0
 //for delegateDemo
 public static void promoteEmployee(List <EmployeeClass> Employees, isPromotable promoDelegate)
 {
     foreach (EmployeeClass emp in Employees)
     {
         if (promoDelegate(emp))
         {
             Console.WriteLine(emp.name);
         }
     }
 }
示例#9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            isPromotable    isPromotable = new isPromotable(Employee.isEligible);
            List <Employee> employees    = new List <Employee>()
            {
                new Employee {
                    Id = 1, salary = 5000, Name = "H", Experience = 5
                },
                new Employee {
                    Id = 2, salary = 6000, Name = "I", Experience = 6
                },
                new Employee {
                    Id = 1, salary = 7000, Name = "J", Experience = 1
                }
            };

            promoteEmployee(employees, isPromotable);
        }