I am working with two classes. MainForm and EmployeeRegistry. In EmployeeRegistry I got a method that adds to a List (addToList).
public void AddToList(...)
{
employeeList.Add(...);
}
In MainForm I created an object of EmployeeRegistry and I want to send another object (with information) into the Emp开发者_如何学CloyeeRegistry.AddToList method to add to the list.
EmployeeRegistry employeeRegistry= new EmployeeRegistry();
employeeRegistry.AddToList(...);
How is this done (on both sides)?
Thankful for all help!
Is this all you're looking for?
public void AddToList(Employee emp)
{
employeeList.Add(emp);
}
And the call:
EmployeeRegistry employeeRegistry = new EmployeeRegistry();
Employee emp = new Employee();
// set information for emp
employeeRegistry.AddToList(emp);
What is the type of employeeList
? In Steven's comment he's assuming List<Employee>
, which I would assume as well. If that's the case, then the AddToList
method should just take an object of type Employee
. Also, it may be good form to overload the method with another one that takes an object of type List<Employee>
and uses AddRange
internally, just for later convenience.
精彩评论