为什么下面的代码会抛出编译错误?根据 C# 4.0 Covariance,不应该允许这样的转换。列出员工列表 = 经理列表;
class Program
{
static void Main(string[] args)
{
List<Manager> managerList = new List<Manager>()
{
new Manager{ FirstName="ASFD", LastName="DSS", NoOfReportees=4},
new Manager{ FirstName="rrr", LastName="dsasde", NoOfReportees=22}
};
List<Employee> employeeList = managerList;
}
}
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Manager:Employee
{
public int NoOfReportees { get; set; }
}