I have a list named employeeList that I am filling with a datatable, which is working correctly. So now I want to the ability to add an (optional) item to the list at runtime. I thought a simple List.Insert would work but I am getting errors when I try to do it. The line I having issues with is the employeeList.Insert and the two errors are included in the code block.
private static List<Employee> employeeList(string store,
string loginId = "",
int position = 100)
{
var employeeList = default(List<Employee>);
employeeList = new List<Employee>();
using (var dt = Logins.getDataset(store, "Manpower_SelectLogins"))
{
foreach (DataRow dr in dt.Rows)
{
employeeList.Add(new Employee(dr["LoginId"].ToString()));
}
}
if (string.IsNullOrEmpty(loginId) != true)
{
employeeList.Insert(position, loginId);
//Error 2 Argument 2: cannot convert from 'string' to
//'ManpowerManager.MainWindow.Employee
//Error 1 The best overloaded method match for
//'System.Collections.Generic.List<ManpowerManager.MainWindow.Employee>.
//Insert(int, ManpowerManager.MainWindow.Employee)' has some invalid arguments
}
return employeeList;
}
What am I doing wrong?
employeeListis a list of typeManpowerManager.MainWindow.Employetherefore you cannot insert a string into it.I think you may want something like this: