Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public void PromoteEmployee(List <Employee> employeeList, IsPromotableDelegate Promote)
 {
     foreach (Employee employee in employeeList)
     {
         if (Promote(employee))
         {
             Console.WriteLine($"{employee.Name} is promoted");
         }
     }
 }
Esempio n. 4
0
 public static void PromoteEmployess(List <Employee> emplList, IsPromotableDelegate isPromotable)
 {
     foreach (Employee emp in emplList)
     {
         if (isPromotable(emp))
         {
             Console.WriteLine(emp.Name + "is promoted");
         }
     }
 }