tags:

views:

32

answers:

2

Hello!

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 EmployeeRegistry.AddToList method to add to the list.

EmployeeRegistry employeeRegistry= new EmployeeRegistry();
employeeRegistry.AddToList(...);

How is this done (on both sides)?

Thankful for all help!

A: 

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.

David
Yes, you both assume right. But how can I code the AddToList so that it will be able to take an object as a parameter and what should I write in the body of the method?
+1  A: 

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);
tzaman
Yes, I think so. Thanks!
You're welcome! :)
tzaman