Beispiel #1
0
 public static void PromoteEmployee(List <Employee> employees, IsPromote isPromote)
 {
     foreach (Employee emp in employees)
     {
         if (isPromote(emp))
         {
             Console.WriteLine(emp.Name);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// ハッシュ値を計算します。
 /// </summary>
 public override int GetHashCode()
 {
     return(
         BWType.GetHashCode() ^
         (DstSquare != null ? DstSquare.GetHashCode() : 0) ^
         (SrcSquare != null ? SrcSquare.GetHashCode() : 0) ^
         (MovePiece != null ? MovePiece.GetHashCode() : 0) ^
         DropPieceType.GetHashCode() ^
         IsPromote.GetHashCode() ^
         SpecialMoveType.GetHashCode());
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            List <Employee> employees = new List <Employee>();

            employees.Add(new Employee {
                Name = "A", Salary = 50000, Experience = 2
            });
            employees.Add(new Employee {
                Name = "B", Salary = 60000, Experience = 3
            });
            employees.Add(new Employee {
                Name = "C", Salary = 30000, Experience = 5
            });
            employees.Add(new Employee {
                Name = "D", Salary = 20000, Experience = 4
            });

            #region use function for delegates
            Console.WriteLine("Use of delegates using functions.");
            Console.WriteLine("Promotion based on sal: ");

            IsPromote isPromoteEmpSal = new IsPromote(IsPromoteEmpSal);
            Employee.PromoteEmployee(employees, isPromoteEmpSal);

            Console.WriteLine();

            Console.WriteLine("Promotion based on experience: ");

            IsPromote isPromoteEmpExp = new IsPromote(IsPromoteEmpExp);
            Employee.PromoteEmployee(employees, isPromoteEmpExp);
            #endregion

            Console.WriteLine();
            Console.WriteLine();

            #region Use lambda expression for delegates
            Console.WriteLine("Use of delegates using lambda expression.");
            Console.WriteLine("Promotion based on sal: ");

            Employee.PromoteEmployee(employees, emp => emp.Salary >= 40000);

            Console.WriteLine();

            Console.WriteLine("Promotion based on experience: ");

            Employee.PromoteEmployee(employees, emp => emp.Experience >= 4);

            #endregion

            Console.ReadLine();
        }