我面臨「公共靜態無效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);'???代表是私人代表 –