我面临“公共静态无效PromoteEmployee(列表employeeList,IsPromotable IsEligibleToPromote)”中的“PromoteEmployee”编译问题。C#:似乎无法将我的头围绕编译错误
如果有人能给我一个关于如何去做这件事的提示,我将不胜感激。
编辑:
错误是: “可访问性不一致:参数类型 'Program.IsPromotable' 比方法更少可访问的 'Program.Employee.PromoteEmployee(列表,Program.IsPromotable)'
class Program
{
static void Main(string[] args)
{
List<Employee> empList = new List<Employee>();
empList.Add(new Employee()
{
ID = 101,
Name = "Test1",
Salary = 5000,
Experience = 5
});
empList.Add(new Employee()
{
ID = 101,
Name = "Test2",
Salary = 2000,
Experience = 1
});
empList.Add(new Employee()
{
ID = 101,
Name = "Test3",
Salary = 4000,
Experience = 4
});
IsPromotable isPromotable = new IsPromotable(Promote);
Employee.PromoteEmployee(empList, isPromotable);
}
public static bool Promote(Employee emp)
{
if (emp.Experience >= 5)
{
return true;
}
else
{
return false;
}
}
delegate bool IsPromotable(Employee empl);
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public int Salary { get; set; }
public int Experience { get; set; }
public static void PromoteEmployee(List<Employee> employeeList, IsPromotable IsEligibleToPromote)
{
foreach (Employee employee in employeeList)
{
if (IsEligibleToPromote(employee))
{
Console.WriteLine(employee.Name + " promoted");
}
}
}
}
}
给我们一个提示,告诉我们编译器错误是什么意思。 – hatchet
什么是错误?它发生了什么?请给我们一些继续。 – Abion47
Is is this line IsPromotable isPromotable = new IsPromotable(Promote);'???代表是私人代表 –