我想从一个不同的.dll类中的方法接收的对象实例化一个列表的新实例。当我这样做,我得到一个类型转换错误:从一个返回列表的方法实例化一个列表
Cannot implicitly convert type System.Collections.Generic.List<HelpDeskBusinessDataObject.Employee> to System.Collections.Generic.List<HelpDeskBusinessUserObject.Employee>
这是怎么了实例吧:
public List<EmployeeBusinessUser> GetAll()
{
EmployeeBusinessData empData = new EmployeeBusinessData();
List<Employee> employees = new List<Employee>();
List<EmployeeBusinessUser> retEmployees = new List<EmployeeBusinessUser>();
try
{
//Here is where I am trying to get the list assigned to what is
//returned from the method call
employees = empData.GetAll();
}
catch (Exception ex)
{
ErrorRoutine(ex, "EmployeeUserData", "GetAll");
}
return retEmployees;
}
感谢您的帮助。
编辑:GETALL()方法:
public List<Employee> GetAll()
{
HelpDeskDBEntities dbContext = new HelpDeskDBEntities();
List<Employee> employees = new List<Employee>();
try
{
employees = dbContext.Employees.ToList();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return employees;
}
'HelpDeskBusinessDataObject'!='HelpDeskBusinessUserObject' – PSL
@ PSL的建议是正确的。你也尝试声明为var? – Jeyara
我知道。我在名为EmployeeBusinessData的类中调用一个名为HelpDeskBusinessDataObjects的项目中的方法。假设我有上面这个方法调用EmployeeBusinessData中的方法,并且能够返回一个员工对象列表。 – Delete