I have three classes in my C# program. Get the following error:
Cannot implicitly convert type 'object' to 'Register_Employee.Employee'. An explicit conversion exists (are you missing a cast?) C:\Users\x64\Documents\Visual Studio 2010\Projects\Register Employee\Register Employee\EmployeeList.cs 20 20 Register Employee
I know what the problem is. You have to return the correct type of object, but I don't know how to solve it. I have a class Employee, a class EmployeeList which holds employees and the main program.
namespace Register_Employee
{
class EmployeeList
{
ArrayList list = new ArrayList();
public void addEmployee(Employee a)
{
this.list.Add(a);
}
public Employee GetEmployee(int Index)
{
var e = list[Index]; <<<<<The problems
return e; <<<<<The problems
}
}
}
namespace Register_Employee
{
class Employee
{
public Employee(String iD, String firstName, String lastName)
{
this.ID = iD;
this.FirstName = firstName;
this.LastName = lastName;
}
public String ID { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
}
}
Thanks in advance
ArrayListwhenList<Employee>would be more descriptive and type safe?